C#:LockBits 推出了一个巨大的红色 X
按照 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.Image = BitmapImage;) 后,出现的只是白色背景上的红色 x,带有红色边框。我做错了什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否忘记在最后调用
UnlockBits
,如本文末尾所建议的:使用LockBits方法访问图像数据?Have you forgotten to call
UnlockBits
at the end, as suggested at the end of this article: Using the LockBits method to access image data?