Question

Following Bob Powell's tutorial on LockBits, I put the following code into 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;
                }
            }
        }

After pushing the Bitmap data into a picturebox (picturebox.Image = BitmapImage;) all that comes out is a red x over a white background, with a red border. What am I doing wrong?

Was it helpful?

Solution

have you forgotten to call UnlockBits at the end as suggested at the end of link http://www.bobpowell.net/lockingbits.htm

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top