Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 锁具发出一个巨大的红色X_C#_Lockbits - Fatal编程技术网

C# 锁具发出一个巨大的红色X

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,

根据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, 
                  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,带有红色边框。我做错了什么?

你是否忘记了在最后调用
解锁位,正如本文结尾所建议的:?

是的,现在它可以工作了。有趣的是,我在问这个问题之前就把它放进去了,调试器不会编译。它告诉我,只有赋值、调用、增量等才能用作语句。谢谢:)