Thursday, November 15, 2001 04:06 PM
Draw the rectangle in XOR mode.
To do this, use Graphics.setXORMode() passing in a color (like Color.blue). Then paint the rectangle. This will display a rectangle that xors each bit with the background image.
The cool thing about XOR is that it has the property of
a ^ b ^ b = a
That may not seem to make any sense, but what it means is that if you have an image, XOR something on top of it, then XOR the same thing again you get the original image back.
So when the cursor moves, if you XOR the same rectangle you painted the last time the old rectangle is erased, leaving the original image.
Because you're using a video stream behind the selection, you may need to be a bit smarter about the redraw. If the video image has changed, you won't want to redraw the last selection rectangle or it will screw up the image...
Hope this helps!