-我在使用Bitmap.SetPixel时遇到异常:
“如果再调用”GetHdc方法后使用Graphics对象,请调用ReleaseHdc方法”
-在VS2005下
using (Bitmap bmp = new Bitmap("1.bmp"))
{
bmp.SetPixel(0, 0, Color.Blue);
}而且在使用MSDN中SetPixel方法的示例的时候也是相同的错误
而且似乎没有直接调用Win32API。 请问怎么回事?
“如果再调用”GetHdc方法后使用Graphics对象,请调用ReleaseHdc方法”
-在VS2005下
using (Bitmap bmp = new Bitmap("1.bmp"))
{
bmp.SetPixel(0, 0, Color.Blue);
}而且在使用MSDN中SetPixel方法的示例的时候也是相同的错误
而且似乎没有直接调用Win32API。 请问怎么回事?
这个语句可以在随便一个ButtonClick事件中测试
而且根据MSDN的Bitmap.SetPixel示例在OnPaint中也不行
试一下就可以看到如果再调用”GetHdc方法后使用Graphics对象,请调用ReleaseHdc方法”的错误
protected override void OnPaint(PaintEventArgs e)
{
Bitmap myBitmap = new Bitmap("1.bmp"); // Draw myBitmap to the screen.
e.Graphics.DrawImage(myBitmap, 0, 0, myBitmap.Width,
myBitmap.Height); // Set each pixel in myBitmap to black.
for (int Xcount = 0; Xcount < myBitmap.Width/10; Xcount++)
{
for (int Ycount = 0; Ycount < myBitmap.Height/10; Ycount++)
{
myBitmap.SetPixel(Xcount, Ycount, Color.Black);
}
} // Draw myBitmap to the screen again.
e.Graphics.DrawImage(myBitmap, 0, 0,
myBitmap.Width, myBitmap.Height); base.OnPaint(e);
}
XP-sp2底下也试了!
都是在“myBitmap.SetPixel(Xcount, Ycount, Color.Black);”语句通过编译,但实例化时弹出错误:未处理InvalidOperationException:
“如果再调用”GetHdc方法后使用Graphics对象,请调用ReleaseHdc方法”
:(
大家都没有这样的情形么?