Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Circular Shaped Images #1174

Open
HemaSudha1498 opened this issue May 31, 2024 · 1 comment
Open

Support for Circular Shaped Images #1174

HemaSudha1498 opened this issue May 31, 2024 · 1 comment

Comments

@HemaSudha1498
Copy link

Exporting profile icons in a circular shape is a common requirement. However, I couldn't find an option to crop images into a circular shape using the Image class.

I tried several methods, including clip paths and Graphics2D objects. The challenge is that I need the cropped images inside a TableCell along with text. One approach that worked involves converting the image to BufferedImage, using a Graphics object, and then converting it back to byte[] to create a new Image instance. However, this process significantly increases the PDF generation time, taking minutes for small data sets and hours for larger ones.

Please enable an optimized way to draw images in circular shapes, or direct me to the relevant code if this functionality is already available.

Screenshot from 2024-05-31 10-45-06

Thank you

@StevenStreasick
Copy link
Contributor

I do agree that this would be a nice feature to have. However, I was able to get a proof of concept for another method for creating circular shaped images, which is hopefully less taxing. I created a mask image, which was of a circular shape, and then I applied that overtop of my original image. This allows for a singular mask to apply to multiple images. While my proof of concept had poorly defined borders around the mask, I believe with a bit of effort, you could create a well defined border.

Image square = Image.getInstance(squareFilePath);
java.awt.Image maskImage = ImageIO.read(new File(maskFilePath));
Image mask = Image.getInstance(maskImage, null, true);
mask.makeMask();
square.setImageMask(mask);

Notice that the mask's original image should be black for when you want a pixel to display, and white for when you do not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants