RE: ArgumentException received when converting a byte array to bitmap
From: mattaku (mattaku_at_discussions.microsoft.com)
Date: 08/17/04
- Next message: Jorge Ribeiro: "Reducing image size dynamicaly"
- Previous message: Suresh Gladstone: "Generic/Text Printer error"
- Next in thread: Frank Hileman: "Re: ArgumentException received when converting a byte array to bitmap"
- Reply: Frank Hileman: "Re: ArgumentException received when converting a byte array to bitmap"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 17 Aug 2004 14:07:03 -0700
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.
"iyuen" wrote:
> 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: Jorge Ribeiro: "Reducing image size dynamicaly"
- Previous message: Suresh Gladstone: "Generic/Text Printer error"
- Next in thread: Frank Hileman: "Re: ArgumentException received when converting a byte array to bitmap"
- Reply: Frank Hileman: "Re: ArgumentException received when converting a byte array to bitmap"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|