开发者

How to create an transparent gif/png image with translucent color patch?

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开发者_如何学C java please guide me friends to achieve this task.


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 sscce of your best effort to the thread as an edit to your question?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜