Skip to main content

Mulitple clip regions

2 replies [Last post]
stenew
Offline
Joined: 2003-08-21
Points: 0

PROBLEM:
I have created an application that will blur an image and display it in a JPanel. I have also created something I call a Spotlight. Basically, it tracks the mouse, and displays a circular region on the blurred image that actually draws the image unblured. I implemented this effect by overriding the paintComponent method thusly:

protected void paintSpotlight(Graphics g)
{
Area clipRegion = new Area( getSpotlight().getArea() );

Graphics2D g2 = ( Graphics2D ) g;
int width = getWidth();
int height = getHeight();

if( getBlurredImage() != null )
{
width = getBlurredImage().getWidth()
height = getBlurredImage().getHeight();
}
g2.drawImage( getBlurredImage(), 0, 0, width, height, null );
g2.setClip( clipRegion );
g2.drawImage( getUnblurredImage(), 0, 0, width, height, null );
}

This all works well.

What I'd like to do now is have multiple Spotlights. In other words, I'd like to have kind of a "swiss cheese" effect, where I have the blurred image with little sections of unblurred image showing in various places.

I've tried looping through the Spotlights and setting the adding to the clip region for each time, but that didn't work. It drew the entire image unblurred.

Any suggestions or pointers would be appreciated.

Thanks,

Steve

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
tarbo
Offline
Joined: 2006-12-18
Points: 0

The issue is likely to be that the clipping shapes are "unioned" together, resulting in a much wider coverage than you intended. For instance, if you have (0,0)-(50,50) and (100,100)-(150,150), then they union together to (0,0)-(150,150), suddenly taking a broad range of other areas in.

You could possibly create a third, component compatible image, and draw into that. It should not have similar clipping issues since you're painting directly rather than via Swing's repaint manager.

Just a thought, really.

Michael Toula

I remember having replied to this one, but it seems my mail get lost
somehow..
There is a mail header that says reply to java2d@javadesktop.org. Is it
correct?
Or should I reply to JAVA2D-INTEREST@JAVA.SUN.COM ?

By the way here is my previous mail...Did you received it previously?

============================================================================================
Steve,

setClip() actually reset the previous clip with the new one and clip()
intersect the current clip with the given shape.
It means that clip() make the current clip "smaller".
Drawing ( draw() or fill() ) the clip on screen is always a good idea to
understand what happens.

g2.setColor(Color.RED);
g2.draw(g2.getClip());

or

g2.setColor(new Color(0,0,0,150));
g2.fill(g2.getClip());

So the clip() method intersect, if you want to add shapes to your clip I
suggest you to have a look at java.awt.geom.Area.
With this class your can build your clip yourself using boolean
operations.

Best,
Mike
============================================================================================

******************************************
Michael TOULA
Software Engineer

Dalim Software GmbH
Strassburger Str. 6
D-77694
Kehl am Rhein
GERMANY

tel: +49 7851 919 612
fax: +49 7851 735 76
web: www.dalim.com
**************************************************************
Dalim Software?s mission is the continued development of innovative
solutions that greater facilitate the production workflow throughput of
media communications companies.
Geschäftsführer (CEO): Dr. Carol Werlé Vorsitzender des Aufsichtsrats
(Chairman): Jim D. Salmon
Ust-IdNr. (VAT-Nr.): DE 195 290 616 Sitz der Gesellschaft (Location):
Kehl, Amtsgericht Freiburg, HRB 371620

java2d@JAVADESKTOP.ORG
Sent by: Discussion list for Java 2D API
15/03/07 23:58
Please respond to
java2d@javadesktop.org

To
JAVA2D-INTEREST@JAVA.SUN.COM
cc

Subject
Re: [JAVA2D] Mulitple clip regions

The issue is likely to be that the clipping shapes are "unioned" together,
resulting in a much wider coverage than you intended. For instance, if
you have (0,0)-(50,50) and (100,100)-(150,150), then they union together
to (0,0)-(150,150), suddenly taking a broad range of other areas in.

You could possibly create a third, component compatible image, and draw
into that. It should not have similar clipping issues since you're
painting directly rather than via Swing's repaint manager.

Just a thought, really.
[Message sent by forum member 'tarbo' (tarbo)]

http://forums.java.net/jive/thread.jspa?messageID=208285

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the
body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".
[att1.html]