Je veux copier BitmapData dans byte [], mais j'obtiens des zéros non existants au milieu du tableau (index 6 et 7). Qu'est ce que je fais mal?Comment puis-je copier BitmapData dans le tableau Byte en utilisant C#?
Bitmap bt = new Bitmap(2, 2, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
for(int ii = 0; ii < bt.Width; ii++)
for(int jj = 0; jj < bt.Height; jj++)
{
int tempVal = (ii + jj * 2)*85;
bt.SetPixel(ii, jj, System.Drawing.Color.FromArgb(tempVal, tempVal, tempVal));
}
Rectangle rect = new Rectangle(0,0,bt.Width, bt.Height);
System.Drawing.Imaging.BitmapData btData = bt.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, bt.PixelFormat);
IntPtr ptr = btData.Scan0;
int bytes = bt.Width * bt.Height * 3;
byte[] rgbValues = new byte[bytes];
System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);
bt.UnlockBits(btData);
for (var ii = 0; ii < bytes; ii++)
System.Diagnostics.Debug.WriteLine(rgbValues[ii]);
//bt.Save("test.png");