469,291 Members | 1,777 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,291 developers. It's quick & easy.

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

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
Nov 18 '05 #1
6 3701
See if this helps: http://vsdntips.com/Tips/VS.NET/Csharp/76.aspx

"hb" <ho****@goodoffices.com> wrote in message
news:OV**************@TK2MSFTNGP14.phx.gbl...
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

Nov 18 '05 #2
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.CleanBase6 4Image(sLabel));
System.IO.MemoryStream memStream=new System.IO.MemoryStream(bitmapData);
System.Drawing.Bitmap bitImage=new
System.Drawing.Bitmap((System.Drawing.Bitmap)Syste m.Drawing.Image.FromStream
(memStream));
bitImage.Save(MapPath("/docs/"+sf));
}
---

Would you please help me to figure out the problem?

Thank you

hb
"Shiva" <sh******@online.excite.com> wrote in message
news:up**************@TK2MSFTNGP12.phx.gbl...
See if this helps: http://vsdntips.com/Tips/VS.NET/Csharp/76.aspx

Nov 18 '05 #3
Hi,
Make sure the Base64 string represents a valid image.

"hb" <ho****@goodoffices.com> wrote in message
news:e4**************@TK2MSFTNGP11.phx.gbl...
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.CleanBase6 4Image(sLabel));
System.IO.MemoryStream memStream=new System.IO.MemoryStream(bitmapData);
System.Drawing.Bitmap bitImage=new
System.Drawing.Bitmap((System.Drawing.Bitmap)Syste m.Drawing.Image.FromStream
(memStream));
bitImage.Save(MapPath("/docs/"+sf));
}
---

Would you please help me to figure out the problem?

Thank you

hb
"Shiva" <sh******@online.excite.com> wrote in message
news:up**************@TK2MSFTNGP12.phx.gbl...
See if this helps: http://vsdntips.com/Tips/VS.NET/Csharp/76.aspx


Nov 18 '05 #4
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" <sh******@online.excite.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi,
Make sure the Base64 string represents a valid image.

"hb" <ho****@goodoffices.com> wrote in message
news:e4**************@TK2MSFTNGP11.phx.gbl...
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.CleanBase6 4Image(sLabel));
System.IO.MemoryStream memStream=new System.IO.MemoryStream(bitmapData);
System.Drawing.Bitmap bitImage=new
System.Drawing.Bitmap((System.Drawing.Bitmap)Syste m.Drawing.Image.FromStream (memStream));
bitImage.Save(MapPath("/docs/"+sf));
}
---

Would you please help me to figure out the problem?

Thank you

hb
"Shiva" <sh******@online.excite.com> wrote in message
news:up**************@TK2MSFTNGP12.phx.gbl...
See if this helps: http://vsdntips.com/Tips/VS.NET/Csharp/76.aspx


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

"hb" <ho****@goodoffices.com> wrote in message
news:uX**************@TK2MSFTNGP12.phx.gbl...
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" <sh******@online.excite.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi,
Make sure the Base64 string represents a valid image.

"hb" <ho****@goodoffices.com> wrote in message
news:e4**************@TK2MSFTNGP11.phx.gbl...
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.CleanBase6 4Image(sLabel));
System.IO.MemoryStream memStream=new System.IO.MemoryStream(bitmapData);
System.Drawing.Bitmap bitImage=new
System.Drawing.Bitmap((System.Drawing.Bitmap)Syste m.Drawing.Image.FromStream (memStream));
bitImage.Save(MapPath("/docs/"+sf));
}
---

Would you please help me to figure out the problem?

Thank you

hb
"Shiva" <sh******@online.excite.com> wrote in message
news:up**************@TK2MSFTNGP12.phx.gbl...
See if this helps: http://vsdntips.com/Tips/VS.NET/Csharp/76.aspx



Nov 18 '05 #6
hb
Shiva,

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

hb
"Shiva" <sh******@online.excite.com> wrote in message
news:er**************@TK2MSFTNGP12.phx.gbl...
Ok, going deeper, what about the stream that you pass to FromStream() - is
it null by chance? Is the bitmapData array ok?

"hb" <ho****@goodoffices.com> wrote in message
news:uX**************@TK2MSFTNGP12.phx.gbl...
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" <sh******@online.excite.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi,
Make sure the Base64 string represents a valid image.

"hb" <ho****@goodoffices.com> wrote in message
news:e4**************@TK2MSFTNGP11.phx.gbl...
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.CleanBase6 4Image(sLabel));
System.IO.MemoryStream memStream=new System.IO.MemoryStream(bitmapData); System.Drawing.Bitmap bitImage=new

System.Drawing.Bitmap((System.Drawing.Bitmap)Syste m.Drawing.Image.FromStream
(memStream));
bitImage.Save(MapPath("/docs/"+sf));
}
---

Would you please help me to figure out the problem?

Thank you

hb
"Shiva" <sh******@online.excite.com> wrote in message
news:up**************@TK2MSFTNGP12.phx.gbl...
See if this helps: http://vsdntips.com/Tips/VS.NET/Csharp/76.aspx



Nov 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by VenuGopal | last post: by
2 posts views Thread by Joey Lee | last post: by
5 posts views Thread by Socrates | last post: by
reply views Thread by Sanjib Biswas | last post: by
6 posts views Thread by PenguinPig | last post: by
3 posts views Thread by Sun | last post: by
4 posts views Thread by =?ISO-8859-2?Q?Boris_Du=B9ek?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.