C# 锁具发出一个巨大的红色X
根据Bob Powell关于锁位的教程,我将以下代码放入C#2010 Visual Studio Express中:C# 锁具发出一个巨大的红色X,c#,lockbits,C#,Lockbits,根据Bob Powell关于锁位的教程,我将以下代码放入C#2010 Visual Studio Express中: System.Drawing.Imaging.BitmapData bmp = BitmapImage .LockBits(new Rectangle(0, 0, 800, 600), System.Drawing.Imaging.ImageLockMode.ReadWrite,
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;
}
}
}
System.Drawing.Imaging.BitmapData bmp=
位图图像
.锁位(新矩形(0,0,800,600),
System.Drawing.Imaging.ImageLockMode.ReadWrite,
MainGrid.PixelFormat)
不安全的
{
对于(int y=0;y
将位图数据推入picturebox(picturebox.Image=BitmapImage;)后,显示的是白色背景上的红色x,带有红色边框。我做错了什么?你是否忘记了在最后调用
解锁位,正如本文结尾所建议的:?是的,现在它可以工作了。有趣的是,我在问这个问题之前就把它放进去了,调试器不会编译。它告诉我,只有赋值、调用、增量等才能用作语句。谢谢:)