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

Discussion in 'ASP .Net' started by hb, Sep 28, 2004.

  1. hb

    hb Guest

    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
     
    hb, Sep 28, 2004
    #1
    1. Advertisements

  2. hb

    Shiva Guest

    See if this helps: http://vsdntips.com/Tips/VS.NET/Csharp/76.aspx

    "hb" <> wrote in message
    news:...
    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
     
    Shiva, Sep 28, 2004
    #2
    1. Advertisements

  3. hb

    hb Guest

    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" <> wrote in message
    news:...
    > See if this helps: http://vsdntips.com/Tips/VS.NET/Csharp/76.aspx
     
    hb, Sep 28, 2004
    #3
  4. hb

    Shiva Guest

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

    "hb" <> wrote in message
    news:...
    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" <> wrote in message
    news:...
    > See if this helps: http://vsdntips.com/Tips/VS.NET/Csharp/76.aspx
     
    Shiva, Sep 28, 2004
    #4
  5. hb

    hb Guest

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

    >
    >
    >
     
    hb, Sep 28, 2004
    #5
  6. hb

    Shiva Guest

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

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

    >
    >
    >
     
    Shiva, Sep 28, 2004
    #6
  7. hb

    hb Guest

    Shiva,

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

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

    > >
    > >
    > >

    >
    >
    >
     
    hb, Sep 28, 2004
    #7
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ignacio Marcos

    need to convert from gif file to jpg file

    Ignacio Marcos, Nov 21, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    415
    Ignacio Marcos
    Nov 21, 2003
  2. David Hearn
    Replies:
    1
    Views:
    700
    Joel Leong
    Mar 5, 2005
  3. Fritz Bayer
    Replies:
    5
    Views:
    24,714
    Fritz Bayer
    Oct 25, 2004
  4. Replies:
    6
    Views:
    88,610
    Mark Space
    Sep 26, 2006
  5. Deephay

    convert an encoded string

    Deephay, Apr 10, 2006, in forum: C Programming
    Replies:
    2
    Views:
    475
    Deephay
    Apr 11, 2006
  6. Guest
    Replies:
    2
    Views:
    912
    Guest
    Jun 20, 2007
  7. Peng Yu
    Replies:
    3
    Views:
    221
  8. Replies:
    10
    Views:
    594
    Miki Tebeka
    Aug 21, 2012
Loading...