在Bob Powell's tutorial on LockBits之后,我将以下代码放入C#2010 Visual Studio Express:
System.Drawing.Imaging.BitmapData bmp =
BitmapImage
.LockBits(new Rectangle(0, 0, 800, 600),
System.Drawing.Imaging.ImageLockMode.ReadWrite,
MainGrid.PixelFormat)
unsafe
{
for (int y = 0; y < bmp.Height; y++)
{
byte* row = (byte*)bmp.Scan0 + (y * bmp.Stride);
for (int x = 0; x < bmp.Width; x++)
{
row[x * 4] = 255;
}
}
}
将Bitmap数据推入图片框(picturebox.Image = BitmapImage;)后,所有出现的都是白色背景上的红色x,带有红色边框。我做错了什么?