Re: ArgumentException received when converting a byte array to bitmap

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Frank Hileman (frankhil_at_no.spamming.prodigesoftware.com)
Date: 08/18/04


Date: Tue, 17 Aug 2004 17:10:06 -0700

The stream for a Bitmap should never be closed. This was probably the source
of your error. The rotations probably disconnected the Bitmap from the
stream, by creating a copy.

Regards,
Frank Hileman

check out VG.net: www.vgdotnet.com
Animated vector graphics system
Integrated Visual Studio .NET graphics editor

"mattaku" <mattaku@discussions.microsoft.com> wrote in message
news:169FEFC2-DEA7-4CA6-B9D1-E67E0A81A379@microsoft.com...
> Hah! I just had this problem and posted something on it. I read on
another
> thread that rotating an image helped them with a similar, but different
bug.
> Here is a snippet of my code that now works:
>
> byte[] byteArray = Convert.FromBase64String( base64String );
> MemoryStream memStrm = new MemoryStream( byteArray, 0, byteArray.Length );
> retObj = Image.FromStream( memStrm );
>
> // these next two lines is to fix a weird C#/.Net bug
> ((Image)retObj).RotateFlip( RotateFlipType.Rotate180FlipNone );
> ((Image)retObj).RotateFlip( RotateFlipType.Rotate180FlipNone );
>
> memStrm.Close();
>
> Why it works, I don't know. I think it is a .Net bug myself. Try it and
> see. Hope this solution isn't too late for your problem.



Relevant Pages

  • Re: Gdi+ Bitmap/Image Clone() function
    ... Once I closed the bitmap, I was able to delete the file. ... constructor Image(IStream*,...) or by means of function Image::FromStream, and why these two functions do not release the stream and should I store the stream all the time untill Image is use. ... If a Bitmap or Image is created from a stream or file or memory chunk, ... the stream or memory stay's "alive" for the life of the Image or Bitmap. ...
    (microsoft.public.win32.programmer.gdi)
  • Re: Gdi+ Bitmap/Image Clone() function
    ... release the stream and should I store the stream all the time untill Image ... If a Bitmap or Image is created from a stream or file or memory chunk, ... I thought of loading from an IStream to be similar from ...
    (microsoft.public.win32.programmer.gdi)
  • Re: Gdi+ Bitmap/Image Clone() function
    ... release the stream and should I store the stream all the time untill ... If a Bitmap or Image is created from a stream or file or memory chunk, ... the stream or memory stay's "alive" for the life of the Image or Bitmap. ...
    (microsoft.public.win32.programmer.gdi)
  • Re: Gdi+ Bitmap/Image Clone() function
    ... Create the stream. ... Now I can safely delete the IStream I created at point 1 and the bitmap is still valid. ... It just uses the stream to read the bitmap - the stream is not raw pixel data, it needs to be a supported image file stream (which can be in memory or on any other stream type). ... Once the objec is created, I want to be able to delete the memory buffer used to create it but, the bitmap object should stay around longer then the memory used to create it. ...
    (microsoft.public.win32.programmer.gdi)
  • Re: Is this the correct way to send a Bitmap over sockets?
    ... // stream is NetworkStream ... Here you don't have to worry about the buffer, ... What if my Bitmap is larger than 1 MB? ...
    (microsoft.public.dotnet.languages.csharp)