ArgumentException thrown when converting a memorystream to image
From: iyuen (iyuen_at_counstruction.ualberta.ca)
Date: 06/16/04
- Next message: Nicholas Paldino [.NET/C# MVP]: "Re: Tray icon in Windows service"
- Previous message: Nicholas Paldino [.NET/C# MVP]: "Re: COM, GAC and Guidelines"
- Next in thread: Jon Skeet [C# MVP]: "Re: ArgumentException thrown when converting a memorystream to image"
- Reply: Jon Skeet [C# MVP]: "Re: ArgumentException thrown when converting a memorystream to image"
- Reply: Nicholas Paldino [.NET/C# MVP]: "Re: ArgumentException thrown when converting a memorystream to image"
- Messages sorted by: [ date ] [ thread ]
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;
}
}
- Next message: Nicholas Paldino [.NET/C# MVP]: "Re: Tray icon in Windows service"
- Previous message: Nicholas Paldino [.NET/C# MVP]: "Re: COM, GAC and Guidelines"
- Next in thread: Jon Skeet [C# MVP]: "Re: ArgumentException thrown when converting a memorystream to image"
- Reply: Jon Skeet [C# MVP]: "Re: ArgumentException thrown when converting a memorystream to image"
- Reply: Nicholas Paldino [.NET/C# MVP]: "Re: ArgumentException thrown when converting a memorystream to image"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|