C#: LockBits显示巨大的红色X

3

根据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中(PictureBox.Image = BitmapImage;),显示的只有一个带红色边框的白色背景和红色“X”符号。我做错了什么?
1个回答

2

是的,现在它可以工作了。有趣的是,在我提出这个问题之前,我就已经加入了这个代码,但调试器无法编译它。它告诉我只有赋值、调用、增量等才能用作语句。谢谢 :) - GunnarJ

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接