问题描述
我正在考虑用Java做两件事的最佳方法:
I'm thinking about the best way to do two things in Java:
- 合并两张图片,背景为.PNG .GIF或.PNG中的另一个(具有透明度并与第一个重叠);
- 将合并后的图像转换为.GIF(透明度)。
我不想渲染它们,只是为了处理java类中的图像并将结果图像写入文件。
I don't want to render them, just to handle the images in the java class and write the resultant image to a file.
任何人都可以帮助我吗?最好的方法是什么?
谢谢!
Can anyone help me? What's the best way to do this?Thank you!
编辑:
谢谢大家的建议!
这就是我最终使用的!非常简单!
Thank you all for the suggestions!This was what I ended up using! Pretty simple!
BufferedImage background = ImageIO.read(new File("image.jpg"));
WritableRaster raster = background.getRaster();
BufferedImage layer = ImageIO.read(new File("overlay.png"));
Graphics2D g2d = (Graphics2D)background.getGraphics();
g2d.drawImage(layer,72,80,null);
关于第二个问题,我仍然无法使用带透明度的.gif扩展名保存。
这个
About the second problem, I still can't save this with .gif extension with transparency.This
ImageIO.write(bufferedImage,"gif",file);
创建.gif图像文件,但它失去了透明度!
有谁知道我该怎么做? JAI也没有gif编码器。
谢谢。
creates the .gif image file but it loses the transparency!Does anyone know how can I do this? JAI also doesn't have the gif encoder.Thank you.
推荐答案
不确定你的应用程序,但如果这是基于服务器的高性能产品,我与使用Java的图像库相比,的结果要好得多。
Not sure of your application, but if this is server-based high performance stuff, I've had much better results shelling out to ImageMagick than using Java's image libraries.
这篇关于Java中的图像处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!