colinodowd
Member
- Joined
- Jan 23, 2020
- Messages
- 12
- Programming Experience
- 1-3
I am having a lot of trouble converting a BagerBG8 byte array to RGB and then populating the RGB image into a pictureBox. I believe the code below solves the transformation to RGB but I cannot get that new byte array to fit inside the pictureBox.
C#:
int src_width = 3840;
int src_height = 2748;
int dst_width = src_width / 2;
int dst_height = src_height / 2;
int col = 0;
int a = 0;
byte[] destination = new byte[dst_width * dst_height * 3];
int pos = 0;
for (int row = 0; row <= dst_width; row += 2)
{
for (col = 0; col < dst_height; col += 2)
{
a = row * src_width + col;
//blue from this line
destination[pos++] = buffer[a];
//green average of two greens from this line and next line:
destination[pos++] = (byte) ((buffer[a + 1] + buffer[a + dst_width]) / 2);
//red from the next line
destination[pos++] = buffer[a + dst_width + 1];
}
}
Bitmap bitmap = bitmap = new Bitmap(1920, 1374, PixelFormat.Format24bppRgb);
BitmapData bmData = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat);
IntPtr pNative = bmData.Scan0;
Marshal.Copy(test, 0, pNative, test.Length);
bitmap.UnlockBits(bmData);
pictureBox1.Image = bitmap;
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
This results in only 1/3 of the pictureBox being filled. Does anybody know what I am doing wrong?
Last edited by a moderator: