From: Calciu on 26 Jun 2008 10:53 Even with BufferedGraphics, BitBlt is faster. I am saying this because with BufferedGraphics you still use g.DrawImage(myBitmap,x,y); wich is slower than BitBlt. I have done tests! If you want to use BitBlt then you must use this approach: [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)] public static extern IntPtr CreateCompatibleDC(IntPtr hDC); [DllImport("gdi32.dll", ExactSpelling = true)] public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject); [DllImport("gdi32.dll", ExactSpelling = true)] public static extern IntPtr DeleteObject(IntPtr hObject); [DllImport("gdi32.dll")] private static extern bool BitBlt(IntPtr hdcDest,Int32 nXDest,Int32 nYDest,Int32 nWidth,Int32 nHeight,IntPtr hdcSrc,Int32 nXSrc,Int32 nYSrc,UInt32 dwRop); private const uint SRCCOPY = 0x00CC0020; IntPtr dcSrc = IntPtr.Zero; Graphics gSrc = null; IntPtr hBitmap = IntPtr.Zero; private Bitmap backImage = null; public Bitmap BackImage { get { return backImage; } set { backImage = value; if (dcSrc != IntPtr.Zero) { gSrc.ReleaseHdc(dcSrc); gSrc.Dispose(); DeleteObject(hBitmap); dcSrc = IntPtr.Zero; } if (backImage != null) { hBitmap = backImage.GetHbitmap(); Graphics clientDC = this.CreateGraphics(); IntPtr hdc = clientDC.GetHdc(); IntPtr memdc = CreateCompatibleDC(hdc); SelectObject(memdc, hBitmap); gSrc = Graphics.FromHdc(memdc); dcSrc = gSrc.GetHdc(); clientDC.ReleaseHdc(hdc); clientDC.Dispose(); } this.Invalidate(); } } protected override void OnPaint(PaintEventArgs e) { Rectangle r = e.ClipRectangle; if (backImage != null && showBackground) { if (r.X > backImage.Width || r.Y > backImage.Height) return; if (r.X + r.Width > backImage.Width) r.Width = backImage.Width - r.X; if (r.Y + r.Height > backImage.Height) r.Height = backImage.Height - r.Y; //e.Graphics.DrawImage(backImage, r, r, GraphicsUnit.Pixel); // the slower GDI+ way IntPtr dcDst = e.Graphics.GetHdc(); BitBlt(dcDst, r.X, r.Y, r.Width, r.Height, dcSrc, r.X, r.Y, SRCCOPY);// the faster GDI BitBlt way e.Graphics.ReleaseHdc(dcDst); } } My problem is how to i release the hBitmap wich is as big as backImage but i'm sure i will find soon.
|
Pages: 1 Prev: MSHTML reference does not work on release machines.. Next: XSL transforms |