Hi
Im trying to speed up my image when scroll. So I want to use p/Invoke and BitBlt insted of GrawImage. But this code doesnt work correctly. What can be the problem?
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
g.TranslateTransform(AutoScrollPosition.X, AutoScrollPosition.Y);
// This goes insted of DrawImage
//Get DC handle and create a compatible one
IntPtr hDC= g.GetHdc();
IntPtr offscreenDC= CreateCompatibleDC(hDC);
// Select our bitmap in to DC, recording what was there before
IntPtr hBitmap = bmp.GetHbitmap();
IntPtr oldObject = SelectObject(offscreenDC, hBitmap);
// Perform blt
BitBlt(hDC, 0, 0, i.Width, i.Height, offscreenDC, AutoScrollPosition.X, AutoScrollPosition.Y, SRCCOPY);
// Select our bitmap object back out of the DC
SelectObject(offscreenDC, oldObject);
// Delete our bitmap
DeleteObject(hBitmap);
// Delete memory DC and release our DC handle
DeleteDC(offscreenDC);
g.ReleaseHdc(hDC);
}
Im trying to speed up my image when scroll. So I want to use p/Invoke and BitBlt insted of GrawImage. But this code doesnt work correctly. What can be the problem?
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
g.TranslateTransform(AutoScrollPosition.X, AutoScrollPosition.Y);
// This goes insted of DrawImage
//Get DC handle and create a compatible one
IntPtr hDC= g.GetHdc();
IntPtr offscreenDC= CreateCompatibleDC(hDC);
// Select our bitmap in to DC, recording what was there before
IntPtr hBitmap = bmp.GetHbitmap();
IntPtr oldObject = SelectObject(offscreenDC, hBitmap);
// Perform blt
BitBlt(hDC, 0, 0, i.Width, i.Height, offscreenDC, AutoScrollPosition.X, AutoScrollPosition.Y, SRCCOPY);
// Select our bitmap object back out of the DC
SelectObject(offscreenDC, oldObject);
// Delete our bitmap
DeleteObject(hBitmap);
// Delete memory DC and release our DC handle
DeleteDC(offscreenDC);
g.ReleaseHdc(hDC);
}