Hex string conversion confusion

Hex string conversion confusion SearchSearch
Author Message
Werner van Aswegen
New member
Username: Jdoe

Post Number: 2
Registered: 01-2006
Posted on Thursday, January 19, 2006 - 11:17 am:   

Okay, so I know that when you want to send a picture message the image has to be converted to a Hex string.

The confusion here is how to do it. I have tried three different methods which all produce different results.

Method 1: Open the image as a filestream then read through it byte by byte, converting every byte into hex.

Method 2: Open the image as a text file and then read through it character by character, building a hex string from each characters ascii(hex) value.

Method 3: Save the image to a memmery stream and the continue as in method 1.

All my code is in ASP.net using VB.Net.

My question is which of these methods is the correct way?

I think that method 1 is correct as this is the only one that I could reverse engineer back to an image.

Next question: Okay. So I have a hex string. What now. I know I'm supposed to use some udh header.

My aim is to send said image with some text. How do I go about this?

Please help me? PLEAAAAASE???
Anonymous
 
Posted on Monday, March 06, 2006 - 09:56 pm:   

deleted by admin 638
Werner van Aswegen
New member
Username: Jdoe

Post Number: 6
Registered: 01-2006
Posted on Tuesday, March 07, 2006 - 07:54 am:   

Well thank you no-one. I have figured it out by myself (and a little help from my friend google). So to all the people that would like to know how to convert an image to hex string (OTA bitmap), here goes.

You will need to know how to work with images to do this. There are some handy examples on www.devshed.com, so just do a search on their site for some help.

Firtsly you are going to need the image to be in grey-scale. So if it isn't you'll need to convert it. After that's done you have to scan through the image pixel by pixel. Start at the top left corner and go from left to right row by row until you reach the bottom right. during this scanning process you need to determine the brightness of the pixel: is it more dark or more light. Dark pixels are given a value of 1 and light pixels a value of 0. create a string variable to hold these values so that after scanning through the entire image you are left with a bunch of one's and zero's or for the technical people out there A Binary string.

To get from the binary string to a hex string you need to group the ones and zero's into groups of four. These groups would have a max decimal value of 15 and a minimum of 0 or in hex: F and 0.

So there you are, you have a hex string that represents the image. Trust me this works as I have done this and sent images via picture messaging successfully.

If you need to know how to convert binary to hex, you are definately not a computer geek. Well done! Here is a bit of code in VB.Net to help you out.

Private Function BinaryToHex(ByRef bin As String) As String
Dim decValue As Double = 0

For x As Integer = 0 To bin.Length - 1
binReversed &= bin.Chars(bin.Length - 1 - x)
decValue += CInt(bin.Chars(bin.Length - 1 - x).ToString) * (2 ^ x)
Next

Return Hex(decValue.ToString)
End Function

I'm not going to educate you as to the technical workings of the above function save to say that it reads through the binary string that is passed to it from right to left, calculates the decimal value for the binary digit in the specific place in the string and then adds it together. Lastly it converts the decimal value to hex. TADA!!!

I hope that this has helped you.

Anonymous
 
Posted on Saturday, April 08, 2006 - 10:50 pm:   

Hi ! I have around 6-7 picture messages in Hex saved in .txt files. How do save them so that my nokia ngage qd opens them as .ota files? I want to forward them as picture messages to other nokia phones. Are there any programs available that can do this? Please help ..