I have a .IMG files.
Specification/description of files is (I translated):
- The IMG binary format consists of N x N pixels, where the size of the individual pixel is 2 syllables of the numeric data type: short (predefined).
What I'm doing now is reading data into byte array and then trying to create BitImage with RGB values.
Byte array looks like this:
[0] 0 byte
[1] 248 byte
[2] 0 byte
[3] 248 byte
[4] 0 byte
...
[414317] 253
[414318] 136
[414319] 254
[414320] 102
[414321] 252
[414322] 135
...
[524287] 248 byte
public static Bitmap GetPictureFromData(int w, int h, byte[] data)
{
Bitmap bmp = new Bitmap(w, h);
int i = 0;
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; x++)
{
int a = 255;
int r = data[i];
int g = data[i+1];
int b = data[i+2];
bmp.SetPixel(x, y, Color.FromArgb(a,r, g, b));
i += 3;
}
}
return bmp;
}
private void button1_Click(object sender, EventArgs e)
{
byte[] file = File.ReadAllBytes("C:\\Users\\user\\Desktop\\glava\\0219.img");
Image img = GetPictureFromData(260, 260, file);
pictureBox1.Image = img;
}
I don't know width and height of image, that's why I have put 260. And I used 260, because if I use greater number i goes out of bounds. I'm doing something wrong, because picture doesn't represent anything. I also used jpg format to test code, but also doesn't work.