Reputation: 288
So I have an application that generates some bitmaps and then stitches them together. This is fine in theory and in small scale but the problem arises when I am stitching considerably large bitmaps together. First of all I cannot generate a bitmap large enough for my bitmaps to fit in. In my algorithm a large bit map is generated which is generated, such that it can hold the others within it, then I paint the other onto it. I am doing all of this in C# and using the System.Drawing.Bitmap
class.
To be specific I noticed the problem in this setup:
Bitmap bmp = new Bitmap(resolution, resolution);
Where resolution = 25000
.
So my question basically boils down to:
Is there an efficient way to join multiple bitmaps together without having to max out memory?
Upvotes: 0
Views: 113
Reputation: 3974
This would require opening and saving data to the file directly. Instead of allocating enough space for the large bitmap, you just use the two smaller ones and stream the proper data directly into the file. Since you are streaming to a file, you aren't actually loading the entire image into one big block of RAM. I won't go into the exact code to do this, but essentially it involves knowing the format of the image (including the header information and such) and understanding how to use file IO streaming for your language.
Upvotes: 3