Convert encoded text to image

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mwwv
    New Member
    • Oct 2009
    • 4

    Convert encoded text to image

    Hi there,

    I would like to process the text of a gif file (when decoded something like GIF89að @÷ € € €€ €€ € €€€€€ÀÀÀÿ ......) back to an image for display in a web page. I have done this with other image types (bmp and jpg), reading in there base64 converted strings, but have not found a way to do this with the gif filetype. Is this at all possible using c# and asp.net, even javascript? Thank you for any advice on this subject.

    Regards,
  • mwwv
    New Member
    • Oct 2009
    • 4

    #2
    Convert encoded text to image

    Hi,

    Is there a way to convert the ascii representation of an image (e.g. BM¶¦ 6 ( € ã   €¦ BAB ...), to display in an image control using C#? Thanks.

    Regards,

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      Create a Bitmap object and set the pixels according to the input data. Depending on the format of your data, you might be able to load a Bitmap object directly from it.

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        Originally posted by mwwv
        Hi,

        Is there a way to convert the ascii representation of an image (e.g. BM¶¦ 6 ( € ã   €¦ BAB ...), to display in an image control using C#? Thanks.

        Regards,
        Basically undo the process that created the ASCII out of the bitmap to turn it back into a bitmap.

        How did you convert the bitmap to an ASCII representation?

        Comment

        • mwwv
          New Member
          • Oct 2009
          • 4

          #5
          Thank you both for your input.

          The purpose of the application is to process MMS messages and display their contents (whatever format it comes in) through a web browser. The MMSs are received as text and the images they contain are therefore displayed as ASCII characters like in the example, so I do not actually do any conversion to ASCII myself. I just need to convert it back. I will look into your suggestions, thanks again.

          Comment

          • tlhintoq
            Recognized Expert Specialist
            • Mar 2008
            • 3532

            #6
            I'm going to guess the data comes in as a stream of bytes.
            Those bytes are being blindly converted to text. Probably something similar to
            Code:
                    public static string ToString(byte[] Bytes)
                    {
                        System.Text.Encoding enc = System.Text.Encoding.ASCII;
                        return enc.GetString(Bytes);
                    }
            Assuming no data has actually been lost, you need to know what the format of the image is supposed to be and try to convert the text to bytes to a bmp.

            Do you have any way of knowing what the image format would be that was sent?
            JPG... GIF.... PNG...
            Indexed color?
            RGB?

            I'm going to guess that you have lost data though. As soon as the byte[] was converted to text it would have been truncated at the first zero byte \0 because that is the "end of string" terminator.

            You need to pull the image out of the raw byte[] before it gets converting to text. Is that an option?

            Comment

            • Plater
              Recognized Expert Expert
              • Apr 2007
              • 7872

              #7
              MMS messages are pretty much like emails. There should be content header declaring the MIME type of the data

              Comment

              • mwwv
                New Member
                • Oct 2009
                • 4

                #8
                Again, thanks for your replies.

                Plater you are correct about the header, I have a sample MMS and I will paste the info below, and this also answers tlhintoq's question regarding the image format as the header indicates this:

                ------=_Part_4629139_ 16129933.124833 9602246
                Content-Type: image/gif;Name=waterf all_gif.gif
                Content-Transfer-Encoding: binary
                Content-Location:waterf all_gif.gif

                GIF89að @÷ € € €€ €€ € €€€€€ÀÀÀÿ ÿ ÿÿ ÿÿ ÿ ÿÿÿÿÿ 3 f ™ Ì ÿ 3 33 3f...

                This particular example indicates a GIF image. This is basically as much info as we get as the MMS's are received as text files.

                Comment

                • Pittaman
                  New Member
                  • Aug 2007
                  • 20

                  #9
                  If you're reading in a base64 encoded binary string (the content of the GIF), decode it and then write it to a wherever you're writing the jpeg and bmp to, it should really be exactly the same for a GIF file I guess.

                  What is the exact problem when doing it with the GIF file as opposed to doing it with a JPEG or BMP?

                  Comment

                  • Plater
                    Recognized Expert Expert
                    • Apr 2007
                    • 7872

                    #10
                    Well then that sounds good, you just need to save the data into a file.
                    Have you tried writing all the binary data to a file and naming it say "waterfall_gif. gif" and seeing if it came out right?

                    Comment

                    Working...