Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to convert a base 64 encoded GIF image to a *.gif file?

Reply
Thread Tools

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

 
 
hb
Guest
Posts: n/a
 
      09-28-2004
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


 
Reply With Quote
 
 
 
 
Shiva
Guest
Posts: n/a
 
      09-28-2004
See if this helps: http://vsdntips.com/Tips/VS.NET/Csharp/76.aspx

"hb" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
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



 
Reply With Quote
 
 
 
 
hb
Guest
Posts: n/a
 
      09-28-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> See if this helps: http://vsdntips.com/Tips/VS.NET/Csharp/76.aspx



 
Reply With Quote
 
Shiva
Guest
Posts: n/a
 
      09-28-2004
Hi,
Make sure the Base64 string represents a valid image.

"hb" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> See if this helps: http://vsdntips.com/Tips/VS.NET/Csharp/76.aspx




 
Reply With Quote
 
hb
Guest
Posts: n/a
 
      09-28-2004
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" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hi,
> Make sure the Base64 string represents a valid image.
>
> "hb" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > See if this helps: http://vsdntips.com/Tips/VS.NET/Csharp/76.aspx

>
>
>



 
Reply With Quote
 
Shiva
Guest
Posts: n/a
 
      09-28-2004
Ok, going deeper, what about the stream that you pass to FromStream() - is
it null by chance? Is the bitmapData array ok?

"hb" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
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" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hi,
> Make sure the Base64 string represents a valid image.
>
> "hb" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > See if this helps: http://vsdntips.com/Tips/VS.NET/Csharp/76.aspx

>
>
>




 
Reply With Quote
 
hb
Guest
Posts: n/a
 
      09-28-2004
Shiva,

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

hb
"Shiva" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Ok, going deeper, what about the stream that you pass to FromStream() - is
> it null by chance? Is the bitmapData array ok?
>
> "hb" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > Hi,
> > Make sure the Base64 string represents a valid image.
> >
> > "hb" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > See if this helps: http://vsdntips.com/Tips/VS.NET/Csharp/76.aspx

> >
> >
> >

>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Freeware to make animated GIF (can Irfanview make an animated GIF?) Annu Pai Digital Photography 4 11-23-2009 12:52 AM
image (jpg,bmp,gif, etc.) convert to equivalent binary representation using vb.net? archieSupremo Software 0 09-06-2009 11:20 AM
Re: filename.gif or filename.gif.jpg? Bergamot HTML 0 05-30-2008 02:56 PM
Re: filename.gif or filename.gif.jpg? Beauregard T. Shagnasty HTML 1 05-30-2008 01:23 PM
How to convert an EPS (Postcript Image) to .GIF or .JPG to display in WebForm? David Hearn ASP .Net 1 03-05-2005 06:38 AM



Advertisments