StrechBlt doesnt work
protected override void OnPaint(PaintEventArgs e)
{
Win32Helper.StretchBlt(this.Handle, 0, 0, 200, 300,bitmap.GetHbitmap(), 0, 0, bitmap.开发者_运维知识库Width, bitmap.Height, Win32Helper.TernaryRasterOperations.SRCCOPY);
this.CreateGraphics().DrawRectangle(new Pen(Color.Black), 0, 0, 100, 100);
base.OnPaint(e);
}
Rectangle is drawn.. But bitmap isnt... I have set picturebox1.Image=bitmap
and works so bitmap isnt empty ... Any idea what am i doing wrong ?
I am in compact framework.
I'm not sure what "this.Handle" is, but it might be not be a handle to a DC. And I suspect you are leaking resources as well with each creation of a Pen and Graphics object. (The garbage collector will release it eventually, but it's not a good idea to leave these handles lingering around). In any case, rather than thunking into StretchBlt, you could just use the Graphics object itself to do the image blit.
protected override void OnPaint(PaintEventArgs e)
{
System.Drawing.Graphics g = e.Graphics; // or call your CreateGraphics function
Pen p = new Pen(Color.Black);
g.DrawImage(bitmap, 0, 0, 200, 300);
g.DrawRectangle(p, 0, 0, 100, 100);
// cleanup
p.Dispose();
// g.Dispose(); Call g.dispose if you allocated it and it didn't come from the PaintEventArgs parameter
base.OnPaint(e);
}
精彩评论