Hello all,
I've got some trouble woth using BitBlt in C#. Basically what I would like to achieve is to BitBlt a Bitmap to the Panel Background, replacing all older graphics previously on the Panel Background.
To acheive without BitBlting I can do:
Graphics g = this.CreateGraphics();
g.Clear(Color.White);
g.DrawImageUnscaled(baseBitmap, 0, 0);
baseBitmap is a BitmapImage I created earlier. This works but there's flickering. Plus I would like something faster. The only alternative would be BitBLT.
Now, If I try BitBlt like this:
Graphics g = Graphics.FromImage(baseBitmapt);
Graphics g2 = this.CreateGraphics();
Bitmap targetBMP = new Bitmap(this.Width, this.Height,g);
Graphics targetG = Graphics.FromImage(targetBMP);
IntPtr targetHDC = targetG.GetHdc();
IntPtr gHDC = g.GetHdc();
IntPtr gHDC2 = g2.GetHdc();
//Copy baseBitmap to targetBMP
BitBlt(targetHDC, 0, 0, this.Width, this.Height, gHDC, 0, 0, 13369376);
//Copy targetBMP to the Panel Background Graphics
BitBlt(gHDC2, 0, 0, this.Width, this.Height, targetHDC, 0, 0, 13369376);
targetG.ReleaseHdc(targetHDC);
g.ReleaseHdc(gHDC);
g2.ReleaseHdc(gHDC2);
All I get as a result is a blank black screen as the Panel Background Image.
Can anyone help me with this please? I tried looking all over the web, but all samples are in C++ and are slightly complex. Plus I'm just looking for something simple so that I can do this quickly.
Any help will be appreciated.
Thanks
Regards
Nathanael