How to convert a base 64 encoded GIF image to a *.gif file?

H

hb

Hi,

Would you please give me some idea to convert/decode a Base 64 encoded GIF
image string to a *.gif file in ASP.Net?

Thank you

hb
 
H

hb

Hi, Shiva,

Thank you for the help!

I tried the code mentioned in the link page you gave me. But I got the
following error:
===
System.ArgumentException: Invalid parameter used. at
System.Drawing.Image.FromStream(Stream stream, Boolean
useEmbeddedColorManagement, Boolean validateImageData) at
System.Drawing.Image.FromStream(Stream stream, Boolean
useEmbeddedColorManagement) at System.Drawing.Image.FromStream(Stream
stream)
===

Here is the code I used:
---
string sLabel=UPS.UPSShipLabelHtml(); //get Base 64 encoded image string
string sTrackNum=UPS.UPSTrackNum();
if(sLabel.Trim().Length>0)
{
string sf="label"+sTrackNum+".gif";
Byte[] bitmapData=new Byte[sLabel.Length];

//take out space and "\r\n" from sLabel
bitmapData=Convert.FromBase64String(UPS.CleanBase64Image(sLabel));
System.IO.MemoryStream memStream=new System.IO.MemoryStream(bitmapData);
System.Drawing.Bitmap bitImage=new
System.Drawing.Bitmap((System.Drawing.Bitmap)System.Drawing.Image.FromStream
(memStream));
bitImage.Save(MapPath("/docs/"+sf));
}
---

Would you please help me to figure out the problem?

Thank you

hb
 
S

Shiva

Hi,
Make sure the Base64 string represents a valid image.

Hi, Shiva,

Thank you for the help!

I tried the code mentioned in the link page you gave me. But I got the
following error:
===
System.ArgumentException: Invalid parameter used. at
System.Drawing.Image.FromStream(Stream stream, Boolean
useEmbeddedColorManagement, Boolean validateImageData) at
System.Drawing.Image.FromStream(Stream stream, Boolean
useEmbeddedColorManagement) at System.Drawing.Image.FromStream(Stream
stream)
===

Here is the code I used:
---
string sLabel=UPS.UPSShipLabelHtml(); //get Base 64 encoded image string
string sTrackNum=UPS.UPSTrackNum();
if(sLabel.Trim().Length>0)
{
string sf="label"+sTrackNum+".gif";
Byte[] bitmapData=new Byte[sLabel.Length];

//take out space and "\r\n" from sLabel
bitmapData=Convert.FromBase64String(UPS.CleanBase64Image(sLabel));
System.IO.MemoryStream memStream=new System.IO.MemoryStream(bitmapData);
System.Drawing.Bitmap bitImage=new
System.Drawing.Bitmap((System.Drawing.Bitmap)System.Drawing.Image.FromStream
(memStream));
bitImage.Save(MapPath("/docs/"+sf));
}
---

Would you please help me to figure out the problem?

Thank you

hb
 
H

hb

Hi, Shiva,

Yes, the Base64 string does represent a valid GIF image.

Do you know why the parameter I used in FromStream() is invalid?
It is a MemoryStream object.

Thank you

hb
Shiva said:
Hi,
Make sure the Base64 string represents a valid image.

Hi, Shiva,

Thank you for the help!

I tried the code mentioned in the link page you gave me. But I got the
following error:
===
System.ArgumentException: Invalid parameter used. at
System.Drawing.Image.FromStream(Stream stream, Boolean
useEmbeddedColorManagement, Boolean validateImageData) at
System.Drawing.Image.FromStream(Stream stream, Boolean
useEmbeddedColorManagement) at System.Drawing.Image.FromStream(Stream
stream)
===

Here is the code I used:
---
string sLabel=UPS.UPSShipLabelHtml(); //get Base 64 encoded image string
string sTrackNum=UPS.UPSTrackNum();
if(sLabel.Trim().Length>0)
{
string sf="label"+sTrackNum+".gif";
Byte[] bitmapData=new Byte[sLabel.Length];

//take out space and "\r\n" from sLabel
bitmapData=Convert.FromBase64String(UPS.CleanBase64Image(sLabel));
System.IO.MemoryStream memStream=new System.IO.MemoryStream(bitmapData);
System.Drawing.Bitmap bitImage=new
System.Drawing.Bitmap((System.Drawing.Bitmap)System.Drawing.Image.FromStream
(memStream));
bitImage.Save(MapPath("/docs/"+sf));
}
---

Would you please help me to figure out the problem?

Thank you

hb
Shiva said:
 
S

Shiva

Ok, going deeper, what about the stream that you pass to FromStream() - is
it null by chance? Is the bitmapData array ok?

Hi, Shiva,

Yes, the Base64 string does represent a valid GIF image.

Do you know why the parameter I used in FromStream() is invalid?
It is a MemoryStream object.

Thank you

hb
Shiva said:
Hi,
Make sure the Base64 string represents a valid image.

Hi, Shiva,

Thank you for the help!

I tried the code mentioned in the link page you gave me. But I got the
following error:
===
System.ArgumentException: Invalid parameter used. at
System.Drawing.Image.FromStream(Stream stream, Boolean
useEmbeddedColorManagement, Boolean validateImageData) at
System.Drawing.Image.FromStream(Stream stream, Boolean
useEmbeddedColorManagement) at System.Drawing.Image.FromStream(Stream
stream)
===

Here is the code I used:
---
string sLabel=UPS.UPSShipLabelHtml(); //get Base 64 encoded image string
string sTrackNum=UPS.UPSTrackNum();
if(sLabel.Trim().Length>0)
{
string sf="label"+sTrackNum+".gif";
Byte[] bitmapData=new Byte[sLabel.Length];

//take out space and "\r\n" from sLabel
bitmapData=Convert.FromBase64String(UPS.CleanBase64Image(sLabel));
System.IO.MemoryStream memStream=new System.IO.MemoryStream(bitmapData);
System.Drawing.Bitmap bitImage=new
System.Drawing.Bitmap((System.Drawing.Bitmap)System.Drawing.Image.FromStream
(memStream));
bitImage.Save(MapPath("/docs/"+sf));
}
---

Would you please help me to figure out the problem?

Thank you

hb
Shiva said:
 
H

hb

Shiva,

I checked the data. bitmapData is OK and memStream.ToArray().Length=1852.
Why FromStream() complaints about the parameter?

hb
Shiva said:
Ok, going deeper, what about the stream that you pass to FromStream() - is
it null by chance? Is the bitmapData array ok?

Hi, Shiva,

Yes, the Base64 string does represent a valid GIF image.

Do you know why the parameter I used in FromStream() is invalid?
It is a MemoryStream object.

Thank you

hb
Shiva said:
Hi,
Make sure the Base64 string represents a valid image.

Hi, Shiva,

Thank you for the help!

I tried the code mentioned in the link page you gave me. But I got the
following error:
===
System.ArgumentException: Invalid parameter used. at
System.Drawing.Image.FromStream(Stream stream, Boolean
useEmbeddedColorManagement, Boolean validateImageData) at
System.Drawing.Image.FromStream(Stream stream, Boolean
useEmbeddedColorManagement) at System.Drawing.Image.FromStream(Stream
stream)
===

Here is the code I used:
---
string sLabel=UPS.UPSShipLabelHtml(); //get Base 64 encoded image string
string sTrackNum=UPS.UPSTrackNum();
if(sLabel.Trim().Length>0)
{
string sf="label"+sTrackNum+".gif";
Byte[] bitmapData=new Byte[sLabel.Length];

//take out space and "\r\n" from sLabel
bitmapData=Convert.FromBase64String(UPS.CleanBase64Image(sLabel));
System.IO.MemoryStream memStream=new System.IO.MemoryStream(bitmapData);
System.Drawing.Bitmap bitImage=new
System.Drawing.Bitmap((System.Drawing.Bitmap)System.Drawing.Image.FromStream
(memStream));
bitImage.Save(MapPath("/docs/"+sf));
}
---

Would you please help me to figure out the problem?

Thank you

hb
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top