[DllImport("gdi32.dll")]
static extern bool BitBlt(
IntPtr hDest,
int XDest,
int YDest,
int WDest,
int HDest,
IntPtr hDCSrc,
int XStart,
int YStart,
int RasterOpCode
);
public static void DrawBitBlt(Graphics g, Bitmap bmp, ref Rectangle destRec)
{
IntPtr hDC= g.GetHdc();
IntPtr hBmp = bmp.GetHbitmap();
IntPtr ImageDC= a.Api.CreateCompatibleDC(hDC);
IntPtr offscreenDC= a.Api.CreateCompatibleDC(hDC);
IntPtr drawBmp= a.Api.CreateCompatibleBitmap(hDC, destRec.Size.Width, destRec.Size.Height);
IntPtr oldBmp= a.Api.SelectObject(ImageDC, hBmp);
IntPtr oldDrawBmp= a.Api.SelectObject(offscreenDC, drawBmp);
if(bmp.Size.Equals(destRec.Size))
{
a.Api.BitBlt(offscreenDC, 0, 0, destRec.Width, destRec.Height, ImageDC, 0, 0, SrcCopy);
}
else
a.Api.StretchBlt(offscreenDC, 0, 0, destRec.Width, destRec.Height, ImageDC, 0, 0, bmp.Width, bmp.Height, SrcCopy);
a.Api.BitBlt(hDC, destRec.X, destRec.Y, destRec.Width, destRec.Height, offscreenDC, 0, 0, SrcCopy);
a.Api.SelectObject(ImageDC, oldBmp);
a.Api.DeleteObject(hBmp);
a.Api.SelectObject(offscreenDC, oldDrawBmp);
a.Api.DeleteObject(drawBmp);
a.Api.DeleteDC(ImageDC);
a.Api.DeleteDC(offscreenDC);
g.ReleaseHdc(hDC);
}