Re: Error Saving Bitmaps when stored in an array?
- From: "Michael C" <nospam@xxxxxxxxxx>
- Date: Sun, 3 Sep 2006 21:16:30 +1000
"shp" <shp@xxxxxxxxxxxxx> wrote in message
news:D2DA339C-3F24-4E89-AEFD-47916BD12929@xxxxxxxxxxxxxxxx
Hi,
I have an array of Bitmap images which I am trying to Serialize. I was
having a problem Serializing the Bitmaps directly (Although I'm not sure
why,
the documentation seems to indicate it is Serializable?) but when I try to
save the Bitmaps from the array structure an error is thrown.
I.e. If I set it up like this:
MemoryStream ms = new MemoryStream();
bmpFrames[0].Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
During runtime I receive the following error:
"A generic error occurred in GDI+."
You will get this error if the *source* of the bitmap has been closed. eg,
if the bitmap was created from a stream and the stream was closed then you
will get that error when saving the bitmap. You can either keep the original
source open, which is a complete pain or create a copy right from the start,
something like this:
Stream stream = GetSomeStream();
Bitmap bitmap = new Bitmap(stream);
Bitmap bitmap2 = new Bitmap(bitmap);
bitmap.Dispose();
stream.Close();
return bitmap2;
For cloning the bitmap I use LockBits with a memcopy, this ensures that
bitmap2 is completely independant of bitmap.
Michael
.
- Prev by Date: Re: Gdi+ error writting bitmap images
- Next by Date: Border Style XP Style on custom controls
- Previous by thread: Re: Gdi+ error writting bitmap images
- Next by thread: Re: Error Saving Bitmaps when stored in an array?
- Index(es):
Relevant Pages
|