Solved

c# want to save large bitmaps

Posted on 2006-10-26
14
2,234 Views
Last Modified: 2008-01-09
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.

0
Comment
Question by:jramrus
  • 6
  • 3
  • 3
  • +1
14 Comments
 
LVL 11

Expert Comment

by:LordWabbit
ID: 17814630
can only suggest that you don't use a bitmap, consider using a compressed format instead like jpeg or gif.
0
 
LVL 11

Expert Comment

by:Expert1701
ID: 17816953
How much data are you working with, or how big is the bitmap you are creating?
0
 
LVL 22

Expert Comment

by:_TAD_
ID: 17820440


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
0
 
LVL 22

Expert Comment

by:_TAD_
ID: 17820441


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
0
 
LVL 22

Expert Comment

by:_TAD_
ID: 17820442


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
0
 
LVL 11

Expert Comment

by:Expert1701
ID: 17820572
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+.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:jramrus
ID: 17820711
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.
0
 
LVL 11

Accepted Solution

by:
Expert1701 earned 100 total points
ID: 17820903
It is certainly possible to create a group of bitmaps and combine them into one large bitmap (for example: 12 bitmaps that are 256 x 256 could be combined in to a single bitmap that is 1024 x 768).  As you are receiving an "out of memory" exception, you can not do this through GDI+ (i.e. System.Drawing.Bitmap, etc.), but you could create your own function.  You will need to work with the bitmap file format directly, and a reference follows.

  The .bmp file format
  http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html
0
 

Author Comment

by:jramrus
ID: 17821226
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.
0
 
LVL 11

Expert Comment

by:Expert1701
ID: 17822334
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.
0
 
LVL 11

Expert Comment

by:Expert1701
ID: 17997418
jramrus, is there anything else we can offer to help solve your question?
0
 

Author Comment

by:jramrus
ID: 17997574
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.
0
 
LVL 11

Expert Comment

by:Expert1701
ID: 17997680
I didn't come across any while searching.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now