Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic SaveToBitmap crash (Read 3625 times)
baron
YaBB Newbies
*
Offline


1001001001

Posts: 42
Joined: Dec 2nd, 2007
SaveToBitmap crash
Oct 4th, 2009 at 4:03pm
Print Post  
A few problems with SaveToBitmap (I am using GDI+ and saving to a .PNG file but all formats seem to have a limitation):

First, there seems to be an undefined limitation on the size of the file. I am trying to figure out how to calculate whether the file would be too large before saving. Any ideas what the exact limitation is?

What I am doing now is that if I see the file wasn't created properly, I adjust ImageExportOptions.ScaleFactor and keep reducing it until it works. Ugly, but at least it works.

And here is the where the crash comes in, when I try saving a huge picture (width=85000 pixels) which fails a few times until I get the ScaleFactor right, there is a huge peak in memory usage which results in app instability. When I try to do this a second time, my application crashes.

So:
1. How do I calculate the exact limitation/size so that I can set the ScaleFactor right?
2. You guys need to check for instability issues on save failure with huge pictures.
  
Back to top
 
IP Logged
 
baron
YaBB Newbies
*
Offline


1001001001

Posts: 42
Joined: Dec 2nd, 2007
Re: SaveToBitmap crash
Reply #1 - Oct 4th, 2009 at 4:16pm
Print Post  
Correction: Even when the save doesn't fail and even if I set ScaleFactor to 1, the app still becomes unstable when I use SaveToBitmap on huge pictures.

What I'm doing now is checking whether the total amount of pixels pass 8500000 and if they do, I reduce the ScaleFactor. This saves the picture fine the first time, but then it crashes on the second round.

I need a solution for this urgently. Thanks in advance.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: SaveToBitmap crash
Reply #2 - Oct 5th, 2009 at 6:11am
Print Post  
Quote:
First, there seems to be an undefined limitation on the size of the file. I am trying to figure out how to calculate whether the file would be too large before saving. Any ideas what the exact limitation is?


We don't have any idea. As you can see in the SaveToBitmap help topic, that's a known problem. The CreateCompatibleBitmap function just returns a null value when called with dimensions and color depth that would require more than 10MB of memory, but we haven't found any reliable way to predict if that will happen (sometimes it works even with larger bitmaps).

Quote:
You guys need to check for instability issues on save failure with huge pictures.


We do everything possible, which is to check for a NULL value in this case before trying to create a file. Indeed the memory peaks, but we can't call DeleteBitmap on the NULL value we receive from the create function.

Quote:
Even when the save doesn't fail and even if I set ScaleFactor to 1, the app still becomes unstable when I use SaveToBitmap on huge pictures.


I don't see this happening in my test. The used memory stays at stable 20MB, and revert to 16MB after the loop completes (on a 1000x1000 bitmap):

Code
Select All
For i = 1 To 100
	fcx.SaveToBitmap diag.fileName + Str(i), fcx.DocLeft, fcx.DocTop, fcx.DocRight, fcx.DocBottom
Next
 



As a solution, you might try exporting multiple bitmaps smaller than 10MB and glue them together using some image processing library. Another option is to export to WMF, which works fine even with huge flowcharts.
  
Back to top
 
IP Logged
 
baron
YaBB Newbies
*
Offline


1001001001

Posts: 42
Joined: Dec 2nd, 2007
Re: SaveToBitmap crash
Reply #3 - Oct 5th, 2009 at 11:41am
Print Post  
Regarding the crash: Sorry, my mistake! I looked deeper and found that it was a combination of things when working with huge charts, causing my code to reference a Box that no longer existed, thus causing a crash.


Regarding the limitations: If I find a certain limit on the amounts of pixels and/or colors, can I assume this limit applies on all machines or does it differ?

If the results are always inconsistent, then I guess my only choice (excluding your suggestion to glue together many pieces) is to keep trying a smaller ScaleFactor until it works?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: SaveToBitmap crash
Reply #4 - Oct 5th, 2009 at 12:22pm
Print Post  
Hi,

From our experience, this limit is different on different systems, e.g. it works with 8000x8000 bitmaps on a test system of ours, but on most it fails around the 3000x3000 boundary (might be related to the size of some buffers in video drivers). I suppose you could count 8MB as the safe upper bound, and run the scaling code for larger bitmaps than that.

Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint