Software Development Network>> Visual C#>> Using C# to restore hex binary data to image?
Is there a way to restore hex binary data to original .BMP image
Thanks.
Hi, James
Thank you for your solution. But I'm wondaring how to convert the array of byte to actual image or there is no way to do it by using C#
Of course, you could compress that down to one line:
Bitmap bmp = new Bitmap(new MemoryStream(HexStringToBytes(str)));
First of all, a number can be represented as Hex digits, or as Binary digits, but it cannot be both at the same time.
Basically, what you have is a string containing hex digits.
I don't know if this is the best way, but it should work:
Using C# to restore hex binary data to image?
Siebe Tolsma
Tamizhan
IanG
Hi, James
Thank you for your solution. But I'm wondaring how to convert the array of byte to actual image or there is no way to do it by using C#
katokay
byte[] byBitmap = HexStringToBytes(str);
MemoryStream ms = new MemoryStream(byBitmap);
Bitmap bmp = new Bitmap(ms);
Of course, you could compress that down to one line:
Bitmap bmp = new Bitmap(new MemoryStream(HexStringToBytes(str)));
LAPM
First of all, a number can be represented as Hex digits, or as Binary digits, but it cannot be both at the same time.
Basically, what you have is a string containing hex digits.
I don't know if this is the best way, but it should work:
byte[] HexStringToBytes(string hex)
{
byte[] data = new byte[hex.Length /2];
int j = 0;
for (int i = 0; i < hex.Length; i+=2)
{
data[ j ] = Convert.ToByte(hex.Substring(x, 2), 16);
++j;
}
return data;
}