0
votes

I want to create gif/png image file using java programatically. This gif/png image should be transparent and a certain patch of color of specified rectangular size and at specified location should be translucent. I have height and width of the image in pixels. I also have x,y coordinate placing that rectangular colored translucent patch and also have the height and width of that colored translucent patch.

Is it possible to create a gif/png image with above specification programatically in Java? How to create such gif/png image?

As I don't know image processing in java please guide me friends to achieve this task.

1
GIF supports transparency but not translucency. For partial transparency, use a PNG.Andrew Thompson

1 Answers

1
votes

Create a BufferedImage with an alpha channel. Get the Graphics object of the image. Paint to it whatever you like. Save it as a PNG using ImageIO.

For documentation, see the JavaDocs for each of those classes. For a tutorial, I recommend the 2D Graphics Trail of the Java Tutorial.

As for demo. code, I am too busy to go trawling through my 'throwaway' codes for an example of creating a PNG with partial transparency. Especially since if I posted it, you'd probably complain that the partially transparent part is a circle rather than a square.

Why not give it your best shot based on the leads I've already provided, and if you get stuck, post an of your best effort to the thread as an edit to your question?