C#:LockBits推出了Giant Red X.

时间:2010-11-27 23:18:33

标签: c# lockbits

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

1 个答案:

答案 0 :(得分:2)

您是否忘记在链接http://www.bobpowell.net/lockingbits.htm

结尾处建议的最后致电UnlockBits