Java中的图像处理 [英] Image handling in Java

查看:158
本文介绍了Java中的图像处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑用Java做两件事的最佳方法:

I'm thinking about the best way to do two things in Java:


  1. 合并两张图片,背景为.PNG .GIF或.PNG中的另一个(具有透明度并与第一个重叠);

  2. 将合并后的图像转换为.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的图像库相比, ImageMagick 的结果要好得多。

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中的图像处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆