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>bHQAAH4AAABCTX4AAAAAAAAAPgAAACgAAAAQAAAAEAAA AAEAAQAAAAAAQAAAAAAAAAAAAA
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;
}
} 8 4395
iyuen <iy***@counstruction.ualberta.ca> 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.:
<snip>
What is "StdPicture format"? It's not a file format I'm familiar with -
and it may not be a format the Bitmap class is familiar with either.
Does your code work with a normal JPEG or GIF converted to Base64 and
put into XML?
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
StdPicture is an VB6 Object that stores bitmap. It's assumed that some
bitmaps are StdPicture object. In fac my task will be....to convert some
code from VB6 to .NET.
In VB6 code, the "picture" are loaded into StdPicture object. My task is to
convert them into Image object in .NET.
--
-----------------------------------------------------------------
Isaac Yuen
CEM
University of Alberta iy***@ualberta.construction.ca
-----------------------------------------------------------------
| University of Alberta
| Phone: (780) 492-2276
| Fax: (780) 492-0249
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om... iyuen <iy***@counstruction.ualberta.ca> 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.:
<snip>
What is "StdPicture format"? It's not a file format I'm familiar with - and it may not be a format the Bitmap class is familiar with either. Does your code work with a normal JPEG or GIF converted to Base64 and put into XML?
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
iyuen <iy***@counstruction.ualberta.ca> wrote: StdPicture is an VB6 Object that stores bitmap. It's assumed that some bitmaps are StdPicture object. In fac my task will be....to convert some code from VB6 to .NET.
In VB6 code, the "picture" are loaded into StdPicture object. My task is to convert them into Image object in .NET.
Well, there are two approaches here:
1) Try your XML/Base64 code with a JPEG
2) Try loading a StdPicture bitmap directly into a Bitmap, without
using XML
My guess is that the first will work and the second won't - in which
case, you'll have to convert all your StdPicture format pictures into a
more standardised format.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
iyuen,
From what I can tell, you are storing the contents of the image in a
PropertyBag, and then taking the Contents property (a byte array), and then
storing that in your file somewhere (or a text encoded version of it).
I've been able to figure out how to do this (it took me a while, but
it's possible).
First, add a reference to msvbvm60.dll. If in VS.NET, go to the
references and add it. Do NOT add it from the list that is given to you on
the "COM" tab. Rather, go to the "COM" tab and browse for the file. This
will cause all of the VB objects to be included in the interop dll.
Once you have that, the following code will read the contents from a
file and place them into a byte array. This byte array will be what was
originally returned to you through the Contents property on the PropertyBag:
// The bytes.
byte[] pbytBytes;
// Read the contents from the file.
using (FileStream pobjStream = new FileStream(@"c:\temp\pic2.txt",
FileMode.Open, FileAccess.Read))
{
// Get the bytes.
pbytBytes = new byte[pobjStream.Length];
// Read the bytes.
pobjStream.Read(pbytBytes, 0, pbytBytes.Length);
}
// Create the property bag.
VBRUN._PropertyBag pobjPropBag = new VBRUN.PropertyBagClass();
// Set the contents.
pobjPropBag.Contents = pbytBytes;
At this point, you need to change it to an Image instance. You can get
the IPictureDisp interface implementation, and then get the image from
there:
// Get the item now. This is an IPictDisp.
stdole.IPictureDisp pobjPicture = (stdole.IPictureDisp)
pobjPropBag.ReadProperty("image", null);
// Now get the image from the handle.
Image pobjImage = Image.FromHbitmap((IntPtr) pobjPicture.Handle, (IntPtr)
pobjPicture.hPal);
And that should be it. Of course, you should do some cleanup (release
the property bag instance, and the picture instance). Other than that, you
should be fine.
Hope this helps
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"iyuen" <iy***@counstruction.ualberta.ca> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl... 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>bHQAAH4AAABCTX4AAAAAAAAAPgAAACgAAAAQAAAAEAAA AAEAAQAAAAAAQAAAAAAAAAAAAA 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;
}
}
Thanks Nicholas. I've been avoiding to use com but i guess it's inevitable.
Do you know why my code doesn't work?
--
-----------------------------------------------------------------
Isaac Yuen
CEM
University of Alberta iy***@ualberta.construction.ca
-----------------------------------------------------------------
| University of Alberta
| Phone: (780) 492-2276
| Fax: (780) 492-0249
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:OJ**************@TK2MSFTNGP11.phx.gbl... iyuen,
From what I can tell, you are storing the contents of the image in a PropertyBag, and then taking the Contents property (a byte array), and
then storing that in your file somewhere (or a text encoded version of it).
I've been able to figure out how to do this (it took me a while, but it's possible).
First, add a reference to msvbvm60.dll. If in VS.NET, go to the references and add it. Do NOT add it from the list that is given to you
on the "COM" tab. Rather, go to the "COM" tab and browse for the file. This will cause all of the VB objects to be included in the interop dll.
Once you have that, the following code will read the contents from a file and place them into a byte array. This byte array will be what was originally returned to you through the Contents property on the
PropertyBag: // The bytes. byte[] pbytBytes;
// Read the contents from the file. using (FileStream pobjStream = new FileStream(@"c:\temp\pic2.txt", FileMode.Open, FileAccess.Read)) { // Get the bytes. pbytBytes = new byte[pobjStream.Length];
// Read the bytes. pobjStream.Read(pbytBytes, 0, pbytBytes.Length); }
// Create the property bag. VBRUN._PropertyBag pobjPropBag = new VBRUN.PropertyBagClass();
// Set the contents. pobjPropBag.Contents = pbytBytes;
At this point, you need to change it to an Image instance. You can
get the IPictureDisp interface implementation, and then get the image from there:
// Get the item now. This is an IPictDisp. stdole.IPictureDisp pobjPicture = (stdole.IPictureDisp) pobjPropBag.ReadProperty("image", null);
// Now get the image from the handle. Image pobjImage = Image.FromHbitmap((IntPtr) pobjPicture.Handle, (IntPtr) pobjPicture.hPal);
And that should be it. Of course, you should do some cleanup (release the property bag instance, and the picture instance). Other than that,
you should be fine.
Hope this helps
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"iyuen" <iy***@counstruction.ualberta.ca> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl... 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>bHQAAH4AAABCTX4AAAAAAAAAPgAAACgAAAAQAAAAEAAA AAEAAQAAAAAAQAAAAAAAAAAAAA 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;
}
}
iyuen,
It doesn't work because you are storing a property bag (which contains a
bitmap) and not the actual bitmap. You need to reconstitute the property
bag in order to get at the bitmap.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"iyuen" <iy***@counstruction.ualberta.ca> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl... Thanks Nicholas. I've been avoiding to use com but i guess it's
inevitable. Do you know why my code doesn't work? -- ----------------------------------------------------------------- Isaac Yuen CEM University of Alberta iy***@ualberta.construction.ca -----------------------------------------------------------------
| University of Alberta | Phone: (780) 492-2276 | Fax: (780) 492-0249 "Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:OJ**************@TK2MSFTNGP11.phx.gbl... iyuen,
From what I can tell, you are storing the contents of the image in a PropertyBag, and then taking the Contents property (a byte array), and then storing that in your file somewhere (or a text encoded version of it).
I've been able to figure out how to do this (it took me a while, but it's possible).
First, add a reference to msvbvm60.dll. If in VS.NET, go to the references and add it. Do NOT add it from the list that is given to you on the "COM" tab. Rather, go to the "COM" tab and browse for the file.
This will cause all of the VB objects to be included in the interop dll.
Once you have that, the following code will read the contents from a file and place them into a byte array. This byte array will be what was originally returned to you through the Contents property on the PropertyBag: // The bytes. byte[] pbytBytes;
// Read the contents from the file. using (FileStream pobjStream = new FileStream(@"c:\temp\pic2.txt", FileMode.Open, FileAccess.Read)) { // Get the bytes. pbytBytes = new byte[pobjStream.Length];
// Read the bytes. pobjStream.Read(pbytBytes, 0, pbytBytes.Length); }
// Create the property bag. VBRUN._PropertyBag pobjPropBag = new VBRUN.PropertyBagClass();
// Set the contents. pobjPropBag.Contents = pbytBytes;
At this point, you need to change it to an Image instance. You can
get the IPictureDisp interface implementation, and then get the image from there:
// Get the item now. This is an IPictDisp. stdole.IPictureDisp pobjPicture = (stdole.IPictureDisp) pobjPropBag.ReadProperty("image", null);
// Now get the image from the handle. Image pobjImage = Image.FromHbitmap((IntPtr) pobjPicture.Handle,
(IntPtr) pobjPicture.hPal);
And that should be it. Of course, you should do some cleanup
(release the property bag instance, and the picture instance). Other than that, you should be fine.
Hope this helps
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"iyuen" <iy***@counstruction.ualberta.ca> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl... 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>bHQAAH4AAABCTX4AAAAAAAAAPgAAACgAAAAQAAAAEAAA AAEAAQAAAAAAQAAAAAAAAAAAAA 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;
}
}
Hey Nicholas....since you're similar with COM...let me ask some more
questions...
Originally I didn't use the propertybag.Content to retrieve the byte array.
I've found some nifty code from a website that allows me to do the same
thing.
Here is the source: http://www.mvps.org/emorcillo/vb6/mu...mpicture.shtml
The output from the code is the same as the byte array i generated using
property bag. Mind you though....I got the exact ArgumentException when I
do the conversion in .NET.
--
-----------------------------------------------------------------
Isaac Yuen
CEM
University of Alberta iy***@ualberta.construction.ca
-----------------------------------------------------------------
| University of Alberta
| Phone: (780) 492-2276
| Fax: (780) 492-0249
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:ur**************@TK2MSFTNGP09.phx.gbl... iyuen,
It doesn't work because you are storing a property bag (which contains
a bitmap) and not the actual bitmap. You need to reconstitute the property bag in order to get at the bitmap.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"iyuen" <iy***@counstruction.ualberta.ca> wrote in message news:%2***************@TK2MSFTNGP11.phx.gbl... Thanks Nicholas. I've been avoiding to use com but i guess it's inevitable. Do you know why my code doesn't work? -- ----------------------------------------------------------------- Isaac Yuen CEM University of Alberta iy***@ualberta.construction.ca -----------------------------------------------------------------
| University of Alberta | Phone: (780) 492-2276 | Fax: (780) 492-0249 "Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:OJ**************@TK2MSFTNGP11.phx.gbl... iyuen,
From what I can tell, you are storing the contents of the image in
a PropertyBag, and then taking the Contents property (a byte array), and then storing that in your file somewhere (or a text encoded version of it).
I've been able to figure out how to do this (it took me a while,
but it's possible).
First, add a reference to msvbvm60.dll. If in VS.NET, go to the references and add it. Do NOT add it from the list that is given to
you on the "COM" tab. Rather, go to the "COM" tab and browse for the file. This will cause all of the VB objects to be included in the interop dll.
Once you have that, the following code will read the contents from
a file and place them into a byte array. This byte array will be what
was originally returned to you through the Contents property on the PropertyBag: // The bytes. byte[] pbytBytes;
// Read the contents from the file. using (FileStream pobjStream = new FileStream(@"c:\temp\pic2.txt", FileMode.Open, FileAccess.Read)) { // Get the bytes. pbytBytes = new byte[pobjStream.Length];
// Read the bytes. pobjStream.Read(pbytBytes, 0, pbytBytes.Length); }
// Create the property bag. VBRUN._PropertyBag pobjPropBag = new VBRUN.PropertyBagClass();
// Set the contents. pobjPropBag.Contents = pbytBytes;
At this point, you need to change it to an Image instance. You
can get the IPictureDisp interface implementation, and then get the image from there:
// Get the item now. This is an IPictDisp. stdole.IPictureDisp pobjPicture = (stdole.IPictureDisp) pobjPropBag.ReadProperty("image", null);
// Now get the image from the handle. Image pobjImage = Image.FromHbitmap((IntPtr) pobjPicture.Handle, (IntPtr) pobjPicture.hPal);
And that should be it. Of course, you should do some cleanup (release the property bag instance, and the picture instance). Other than
that, you should be fine.
Hope this helps
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"iyuen" <iy***@counstruction.ualberta.ca> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl... > 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>bHQAAH4AAABCTX4AAAAAAAAAPgAAACgAAAAQAAAAEAAA AAEAAQAAAAAAQAAAAAAAAAAAAA > 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; > > } > > } > >
Hey Nick....
i've used SavePicture() method from this site http://www.mvps.org/emorcillo/vb6/mu...mpicture.shtml to
convert the StdPicture too. Same result....I get an ArgumentException
("Invalid parameter used").
Do you have any clue?
--
-----------------------------------------------------------------
Isaac Yuen
CEM
University of Alberta iy***@ualberta.construction.ca
-----------------------------------------------------------------
| University of Alberta
| Phone: (780) 492-2276
| Fax: (780) 492-0249
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:ur**************@TK2MSFTNGP09.phx.gbl... iyuen,
It doesn't work because you are storing a property bag (which contains
a bitmap) and not the actual bitmap. You need to reconstitute the property bag in order to get at the bitmap.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"iyuen" <iy***@counstruction.ualberta.ca> wrote in message news:%2***************@TK2MSFTNGP11.phx.gbl... Thanks Nicholas. I've been avoiding to use com but i guess it's inevitable. Do you know why my code doesn't work? -- ----------------------------------------------------------------- Isaac Yuen CEM University of Alberta iy***@ualberta.construction.ca -----------------------------------------------------------------
| University of Alberta | Phone: (780) 492-2276 | Fax: (780) 492-0249 "Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:OJ**************@TK2MSFTNGP11.phx.gbl... iyuen,
From what I can tell, you are storing the contents of the image in
a PropertyBag, and then taking the Contents property (a byte array), and then storing that in your file somewhere (or a text encoded version of it).
I've been able to figure out how to do this (it took me a while,
but it's possible).
First, add a reference to msvbvm60.dll. If in VS.NET, go to the references and add it. Do NOT add it from the list that is given to
you on the "COM" tab. Rather, go to the "COM" tab and browse for the file. This will cause all of the VB objects to be included in the interop dll.
Once you have that, the following code will read the contents from
a file and place them into a byte array. This byte array will be what
was originally returned to you through the Contents property on the PropertyBag: // The bytes. byte[] pbytBytes;
// Read the contents from the file. using (FileStream pobjStream = new FileStream(@"c:\temp\pic2.txt", FileMode.Open, FileAccess.Read)) { // Get the bytes. pbytBytes = new byte[pobjStream.Length];
// Read the bytes. pobjStream.Read(pbytBytes, 0, pbytBytes.Length); }
// Create the property bag. VBRUN._PropertyBag pobjPropBag = new VBRUN.PropertyBagClass();
// Set the contents. pobjPropBag.Contents = pbytBytes;
At this point, you need to change it to an Image instance. You
can get the IPictureDisp interface implementation, and then get the image from there:
// Get the item now. This is an IPictDisp. stdole.IPictureDisp pobjPicture = (stdole.IPictureDisp) pobjPropBag.ReadProperty("image", null);
// Now get the image from the handle. Image pobjImage = Image.FromHbitmap((IntPtr) pobjPicture.Handle, (IntPtr) pobjPicture.hPal);
And that should be it. Of course, you should do some cleanup (release the property bag instance, and the picture instance). Other than
that, you should be fine.
Hope this helps
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"iyuen" <iy***@counstruction.ualberta.ca> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl... > 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>bHQAAH4AAABCTX4AAAAAAAAAPgAAACgAAAAQAAAAEAAA AAEAAQAAAAAAQAAAAAAAAAAAAA > 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; > > } > > } > >
This discussion thread is closed Replies have been disabled for this discussion. Similar topics
1 post
views
Thread by halise irak via .NET 247 |
last post: by
|
1 post
views
Thread by Arcnet |
last post: by
|
reply
views
Thread by CroDude |
last post: by
|
3 posts
views
Thread by Hitesh |
last post: by
|
13 posts
views
Thread by Don |
last post: by
|
1 post
views
Thread by Martin Widmer |
last post: by
|
3 posts
views
Thread by Raghu Raman |
last post: by
|
6 posts
views
Thread by =?Utf-8?B?QkJN?= |
last post: by
|
2 posts
views
Thread by Bjorn Sagbakken |
last post: by
| | | | | | | | | | |