Following Bob Powell’s LockBits tutorial , I introduced the following code in 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 clicking the bitmap data into the picture box (picturebox.Image = BitmapImage;) all that comes out is red x on a white background with a red frame. What am I doing wrong?
source
share