Link to home
Start Free TrialLog in
Avatar of jramrus
jramrus

asked on

c# want to save large bitmaps

I believe this is an easy question. I currently make a bitmap object and then save it to disk. If the amount of data I am trying to turn into a bitmap is too large, my application complains with an 'out of memory' error. Is there a simple way to do this in pieces, meaning make a part of the bitmap image, save it to disk, make the next part, save it to disk, etc. etc.

Avatar of LordWabbit
LordWabbit

can only suggest that you don't use a bitmap, consider using a compressed format instead like jpeg or gif.
How much data are you working with, or how big is the bitmap you are creating?


Just before you convert your data to bmp, you may want to run the Garbage Collector.  

GC.Collect()

Generally it's not a good idea to run the garbage collector because it adds overhead.  but if you want to clear up some memory for a large process, GC.Collect may be an easy fix


Just before you convert your data to bmp, you may want to run the Garbage Collector.  

GC.Collect()

Generally it's not a good idea to run the garbage collector because it adds overhead.  but if you want to clear up some memory for a large process, GC.Collect may be an easy fix


Just before you convert your data to bmp, you may want to run the Garbage Collector.  

GC.Collect()

Generally it's not a good idea to run the garbage collector because it adds overhead.  but if you want to clear up some memory for a large process, GC.Collect may be an easy fix
What kind of data are you turning in to a bitmap?  Can you provide a sample?  It may be easy to create the bitmap directly instead of depending on GDI+.
Avatar of jramrus

ASKER

I'm talking about the 300Mb range being shoved into the bitmap function. I do not believe running the gc.collect will help, all it will potentially do is delay the threshold where it starts failing. I'm hoping for something that will allow me to create huge bitmaps by writing them one piece at a time. I imagine it will be slower, but I had to guess it was an option. Maybe not??

It is just image data, nothing fancy about the data itself.
ASKER CERTIFIED SOLUTION
Avatar of Expert1701
Expert1701

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jramrus

ASKER

Can you still use the c# 'bitmap' function in conjunction with this to do the compression? Or is this just a way to do the entire bitmap file writing by hand?

Yes, I am receiving an 'out of memory' exception, and I am under the assumption that the error actually means I am out of memory.
This is a way to create the entire bitmap "by hand."  You can use it to write a method that would combine multiple small images that have been saved to disk, into one large image.
jramrus, is there anything else we can offer to help solve your question?
Avatar of jramrus

ASKER

so is there an open-source project or existing library that exists that allows you to write in a bitmap in pieces? I always knew I could write the bitmap by 'hand', but I was hoping that there was a better option.
I didn't come across any while searching.