Skip to main content

IMage with rounder border

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
2 replies [Last post]
bjcoredev
Offline
Joined: 2008-06-13

Hi

I want display user avatars in my app with round corners.

How can i make round corner on a existing images like http://www.roundpic.com/

Thx

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
vprise
Offline
Joined: 2003-11-07

If I understand correctly you want to actually change the image not just set the border to rounded border right?

To change the image do something like this:

</p>
<p>// do this code once in the application and reuse the globalMaskImage variable. You can create the mask image in photoshop to get anti-aliasing etc.</p>
<p>Image mask = Image.createImage(width, height);        </p>
<p>Graphics g = mask.getGraphics();        </p>
<p>g.setColor(0);        </p>
<p>g.fillRect(0, 0, mask.getWidth(), mask.getHeight());        </p>
<p>g.setColor(0xffffff);        </p>
<p>g.fillRoundRect(0, 0, mask.getWidth(), mask.getHeight(), 12, 12);        </p>
<p>globalMaskImage = mask.createMask();</p>
</p>
<p>// use this code when you want to round the image</p>
<p>Image roundedImage = squareImage.applyMask(globalMaskImage);</p>
<p>

Keep in mind that the rounded image will take up more space in RAM as a result and that the cost of rounding is expensive so don't do it in the renderer!

bjcoredev
Offline
Joined: 2008-06-13

That is exactly what i wanted. It works fine

Thank you very much