【发布时间】:2010-02-20 14:51:27
【问题描述】:
我正在尝试使用此代码将Bitmap 直接绘制到PictureBox 上:
Bitmap bmp = (Bitmap)Bitmap.FromFile(@"C:\Users\Ken\Desktop\Load2.bmp");
Graphics grDest = Graphics.FromHwnd(pictureBox1.Handle);
Graphics grSrc = Graphics.FromImage(bmp);
IntPtr hdcDest = grDest.GetHdc();
IntPtr hdcSrc = grSrc.GetHdc();
BitBlt(hdcDest, 0, 0, pictureBox1.Width, pictureBox1.Height,
hdcSrc, 0, 0, (uint)TernaryRasterOperations.SRCCOPY); // 0x00CC0020
grDest.ReleaseHdc(hdcDest);
grSrc.ReleaseHdc(hdcSrc);
但不是渲染Bitmap 的内容,它只是绘制一个近乎黑色的实心块。我很确定问题出在源 hDC 上,因为如果我在上面的代码中将 SRCCOPY 更改为 WHITENESS,它会按预期绘制一个纯白色块。
注意:下一个 sn-p 工作正常,所以位图本身没有问题:
Bitmap bmp = (Bitmap)Bitmap.FromFile(@"C:\Users\Ken\Desktop\Load2.bmp");
pictureBox1.Image = bmp;
【问题讨论】:
标签: c# .net gdi+ pinvoke bitblt