按照Bob Powell关于LockBits的教程,我将以下代码放入C# 2010 Visual Studio速成版中:
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 (picturebox.Image = BitmapImage;)之后,所有出来的都是一个红色的x,白色背景上有一个红色边框。我做错了什么?
发布于 2010-11-28 07:28:39
您是否忘记了按照本文末尾的建议在最后调用UnlockBits:Using the LockBits method to access image data
https://stackoverflow.com/questions/4294452
复制相似问题