GDI+, BitBlt instead of DrawImage

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
 
C

Casey Leamon

Perhaps the Graphics context that you load the bitmap into from file, is
not the same graphics context you get from the PaintEventArgs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top