Connecting Tech Pros Worldwide Forums | Help | Site Map

Convert encoded text to image

Newbie
 
Join Date: Oct 2009
Posts: 4
#1: Oct 1 '09
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,

Newbie
 
Join Date: Oct 2009
Posts: 4
#2: Oct 6 '09

re: 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,
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#3: Oct 6 '09

re: Convert encoded text to image


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.
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,783
#4: Oct 6 '09

re: Convert encoded text to image


Quote:

Originally Posted by mwwv View Post

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?
Newbie
 
Join Date: Oct 2009
Posts: 4
#5: Oct 8 '09

re: Convert encoded text to image


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.
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,783
#6: Oct 9 '09

re: Convert encoded text to image


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
Expand|Select|Wrap|Line Numbers
  1.         public static string ToString(byte[] Bytes)
  2.         {
  3.             System.Text.Encoding enc = System.Text.Encoding.ASCII;
  4.             return enc.GetString(Bytes);
  5.         }
  6.  
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?
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#7: Oct 9 '09

re: Convert encoded text to image


MMS messages are pretty much like emails. There should be content header declaring the MIME type of the data
Newbie
 
Join Date: Oct 2009
Posts: 4
#8: Oct 14 '09

re: Convert encoded text to image


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.1248339602246
Content-Type: image/gif;Name=waterfall_gif.gif
Content-Transfer-Encoding: binary
Content-Location:waterfall_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.
Pittaman's Avatar
Newbie
 
Join Date: Aug 2007
Location: Belgium
Posts: 20
#9: Oct 15 '09

re: Convert encoded text to image


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?
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#10: Oct 15 '09

re: Convert encoded text to image


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?
Reply