ArgumentException thrown when converting a memorystream to image

From: iyuen (iyuen_at_counstruction.ualberta.ca)
Date: 06/16/04


Date: Wed, 16 Jun 2004 08:31:59 -0600

I'm having problems with converting a byte array to an image object~

My byte array is an picture in VB6 StdPicture format. I've used propertybag
to convert the picture into base64Array format in XML, and embedded
the array as some child element in an xml file, i.e.:

<Mask>bHQAAH4AAABCTX4AAAAAAAAAPgAAACgAAAAQAAAAEAAAAAEAAQAAAAAAQAAAAAAAAAAAAA
AA AAAAAAAAAAAAAAAA////AP//AAD//wAA//8AAP//AAD/7wAA//cAALtzAABVeQAAVUAAAFVA
AABVeQAAtDMAAP/3AAD/7wAA//8AAP//AAA=</Mask>

As I read the xml file in .NET, I parse my xml, retrieve this string, and
try to convert it into an Image object or Bitmap in the following code.
However, as I try to return the Bitmap object in the try/catch block, an
ArgumentException ("Invalid parameters used") is always thrown. I've used
an alternative route i.e "return Image.FromStream(bitmapData)" but I always
receive an exception.

I've search numerous times in googld about this problem but no one has a
firm grip of what's going on. So do all of your C#/.NET guru can tell me
what's going on and what I should do to get it to work?

I've seen a post on the web that suggests I may need a bitmap header in my
array. If that's so...how should I encode it?

Thanks,
internal static Bitmap convertImage(string imageText){

    imageText = imageText.Replace("\r\n", String.Empty);

    Byte[] bitmapData;

    bitmapData = Convert.FromBase64String(imageText);

    MemoryStream streamBitmap = new MemoryStream(bitmapData);

    try

    {

        return new Bitmap(streamBitmap);

    }

    catch (ArgumentException e)

    {

        throw e;

    }

}



Relevant Pages

  • RE: ArgumentException received when converting a byte array to bitmap
    ... thread that rotating an image helped them with a similar, but different bug. ... > My byte array is an picture in VB6 StdPicture format. ... > the array as some child element in an xml file, ... > try to convert it into an Image object or Bitmap in the following code. ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: ArgumentException thrown when converting a memorystream to image
    ... the following code will read the contents from a> file and place them into a byte array. ... >> As I read the xml file in .NET, I parse my xml, retrieve this string, and>> try to convert it into an Image object or Bitmap in the following code. ...
    (microsoft.public.dotnet.languages.csharp)
  • ArgumentException received when converting a byte array to bitmap
    ... My byte array is an picture in VB6 StdPicture format. ... the array as some child element in an xml file, ... try to convert it into an Image object or Bitmap in the following code. ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: ArgumentException thrown when converting a memorystream to image
    ... PropertyBag, and then taking the Contents property (a byte array), and then ... > As I read the xml file in .NET, I parse my xml, retrieve this string, and> try to convert it into an Image object or Bitmap in the following code. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: ArgumentException thrown when converting a memorystream to image
    ... bitmap) and not the actual bitmap. ... bag in order to get at the bitmap. ... >> file and place them into a byte array. ... >>> try to convert it into an Image object or Bitmap in the following code. ...
    (microsoft.public.dotnet.languages.csharp)

Loading