what s wrong with my BitBlt XOR method ?

  • Thread starter ΢ÈíÐÂÎÅ×é
  • Start date
Î

΢ÈíÐÂÎÅ×é

PrevSCRBmp is defined to hold the last time screen copy.
and in XORBmp placed the result of BitBlt XOR function.
after buttonclick_event first time, PrevSCRBmp holds the first screen Copy
by BitBlt(SRCCOPY) method.
and second time,after BitBlt(SRCINVERT) method,i thought XORBmp should be
black in most area because the screen did not change at all.But the XORBmp
looks like a direct screen copy,the XOR method doesnt work.

i dont know why.Here is my code:
////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////
private Bitmap PrevSCRBmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height);
//to store screen shot last time
public Bitmap GetXORImage(Bitmap prevScreenBmp)
{

IntPtr dcScreen = GetDC(IntPtr.Zero);
Graphics g1 = Graphics.FromHdc(dcScreen);
Rectangle rect = new Rectangle();
rect = Screen.PrimaryScreen.Bounds;
Bitmap XORBmp = prevScreenBmp ; // XORBmp stores the XOR result,and it
must be assigned from prevScreenBmp in order to
// compare with coming screen shot
Graphics g2 = Graphics.FromImage ( XORBmp ) ;
//get screen 's DC
IntPtr dc1 = g1.GetHdc();
//get XORBmp 's DC
IntPtr dc2 = g2.GetHdc ( ) ;
// to do this step to realize XOR method
BitBlt( dc2 , 0 , 0 , rect.Width , rect.Height , dc1 , 0 , 0 , 6684742);

g1.ReleaseHdc ( dc1 ) ;
g2.ReleaseHdc ( dc2 ) ;
//////////////////////////////
g1.Dispose();
g2.Dispose();
return XORBmp; // then XORBmp should be the result of XOR screen copy
}

private void button5_Click(object sender, System.EventArgs e)
{
Bitmap xorb = this.GetXORImage(PrevSCRBmp);

////////////////////////////////////get the curren screen shot to compare
with next screen shot ///
IntPtr dcScreen = GetDC(IntPtr.Zero);
Graphics g1 = Graphics.FromHdc(dcScreen);
Graphics g3 = Graphics.FromImage(PrevSCRBmp);
IntPtr dc1 = g1.GetHdc();
IntPtr dc3 = g3.GetHdc();

BitBlt(dc3,0,0,Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds
..Height,dc1,0,0,13369376);
g3.ReleaseHdc(dc3);
g3.Dispose();
g1.ReleaseHdc(dc1);
g1.Dispose();
/////////////////////////////////////////////////////////////

}
 
Joined
Jul 10, 2011
Messages
1
Reaction score
0
Hi Mate.

How did you solve that problem with SRCINVERT

Seems like it doesnt work since 2004 :):bow:
 

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