Reputation: 7174
I have such a string :
string x = 0x424D3630090000000000360010028000000C00100200011111111111333333333000000C40E0000C40E000000088888888BBBBCC262281FF231F7EFF251D81FF....."
I'm told to convert this string to JPEG image, I'm not sure about the actual data type of this string and I don't know how to convert it to JPEG. Could you give me at least a few tips about that? Thanks in advance.
EDIT:
I converted the string to byte Array like this :
byte[] bytes = Convert.FromBase64String("0x424D363009..");
And I get this exception :
Invalid length for a Base-64 char array or string.
Upvotes: 0
Views: 3725
Reputation: 7213
One more possible solution, you can get byte[]
from that HEX string using:
string x = GetYouHexString();
x = x.Remove(0,2);
string[] stringArr = Enumerable.Range(0, x.Length / 2)
.Select(i => x.Substring(i * 2, 2))
.ToArray();
byte[] byteArr = Array.ConvertAll(stringArr , b => Convert.ToByte(b, 16));
then save it using MemoryStream
and Image
:
using(Image image = Image.FromStream(new MemoryStream(byteArr)))
{
image.Save("output.jpg", ImageFormat.Jpeg);
}
Upvotes: 3