按照 Bob Powell 的 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;
}
}
}
将位图数据推送到图片框 (picturebox.Image = BitmapImage;) 后,所有出来的都是白色背景上的红色 x,带有红色边框。我究竟做错了什么?