GDI+, BitBlt & DrawImage

  • Thread starter Thread starter Ivan
  • Start date Start date
I

Ivan

Hi there

I'm trying to use BitBlt function instead od DrawImage beacuse I need speed
in my app. I have one Bitmap (bmp) that is loaded from file and I use it in
OnPaint for drawing. Currently I use this code, but it does not work (it
draws only black). What am I missing ?!

public int LoadImage (string strFileName)
{
// load bitmap
bmp=new Bitmap (strFileName);
this.CreateGraphics().DrawImage (bmp,0,0);
}

private void EasyFormCtrl_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
if (bmp!=null)
{
Graphics g2 = Graphics.FromImage(bmp);
IntPtr dc1 = e.Graphics.GetHdc();
IntPtr dc2 = g2.GetHdc();

BitBlt(dc1, e.ClipRectangle.Left, e.ClipRectangle.Top,
e.ClipRectangle.Width, e.ClipRectangle.Height,
dc2, e.ClipRectangle.Left, e.ClipRectangle.Top, 0x00CC0020);
//SRCCOPY (DWORD)0x00CC0020 dest = source

e.Graphics.ReleaseHdc(dc1);
g2.ReleaseHdc(dc2);

// -> this code works ok, but it is slow !!!
// GraphicsUnit units = GraphicsUnit.Pixel;
// e.Graphics.DrawImage (bmp, e.ClipRectangle, e.ClipRectangle, units);
// <-
}
}


Best regards,
Ivan
 
Back
Top