Selection Rectangle on a Canvas
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Amit_Rosner
Posted On:   Monday, November 5, 2001 07:31 AM

Hi! I wish to draw a selection rectangle on a canvas, when I drag the mouse. The regular way to do that was, of course, to use the pair clearRect(x, y, w+1, h+1) and drawRect(x, y, w, h), as described in http://www.jguru.com/faq/view.jsp?EID=139063 My problem is, that my canvas is displaying online video stream, from an underlying native CPP Dll, through a JNI interface. So - when I drag the mouse to display a selection rectangle, it displays the rectangle, but erases all of the pixels inside the rectangle, that were displayed from the video stream. Can anyone tell me how to solve this problem?    More>>

Hi!



I wish to draw a selection rectangle on a canvas, when I drag the mouse.


The regular way to do that was, of course, to use the pair clearRect(x, y, w+1, h+1) and drawRect(x, y, w, h), as described in http://www.jguru.com/faq/view.jsp?EID=139063



My problem is, that my canvas is displaying online video stream, from an underlying native CPP Dll, through a JNI interface.



So - when I drag the mouse to display a selection rectangle, it displays the rectangle, but erases all of the pixels inside the rectangle, that were displayed from the video stream.



Can anyone tell me how to solve this problem?

   <<Less

Re: Selection Rectangle on a Canvas

Posted By:   Scott_Stanchfield  
Posted On:   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!

About | Sitemap | Contact