[DllImport("gdi32.dll")] //Included in 95 and later.
static extern bool BitBlt(
IntPtr hDest, // handle to destination DC
int XDest, // x-coord of destination upper-left corner
int YDest, // y-coord of destination upper-left corner
int WDest, // width of destination rectangle
int HDest, // height of destination rectangle
IntPtr hDCSrc, // handle to source DC
int XStart, // x-coordinate of source upper-left corner
int YStart, // y-coordinate of source upper-left corner
int RasterOpCode // raster operation code
);
//------------------------------
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);
}