使用Java进行图像处理 [英] Image manipulation using java
问题描述
我正在尝试创建一个程序来生成用作多屏背景的图像,我针对的是Windows(在我的情况下为7,因此基本上我可以更改图像而不会看到相同的图像)在两个不同的屏幕上)
i'm trying to create a program that generates images for use as multi-screen backgrounds, i'm doing this targeted at windows (in my case, 7 so that basically i can get images to change without seeing the same image on two different screens)
在我的程序中,我读取了多个图像输入文件,并将它们编译成一个输出图像,该图像等于桌面的总大小(包括屏幕上看不到的黑色区域)
in my program, i read multiple image input files and compile them into a single output image that is the total size of the desktop (including black areas not seen on screens)
我的问题是,什么类/方法适合于裁剪/调整大小/粘贴到Java中的新图像中,因为我遇到了太多的图像操作类,它们似乎都做不到一件事.
my question is, what class/methods are good for cropping/resizing/pasting into a new image in java because i'm coming across so many image manipulation classes and they all seem to do one tiny thing.
除了调整大小或裁剪以外,我不会修改任何图像并将其放置在新(最初为空白)图像中的某个位置.
i will not be modifying any of the images beyond resize or crop and putting it into a certain position in the new (initially blank) image.
代码可以提供,因为我计划在以后的某个时间点将其发布给可能喜欢/需要它的人.
code can be made available as i plan to release it at some later point for whoever may like/need it.
预先感谢您,如果这个问题已得到回答,我深表歉意,但我还是四处看看.
thank you in advance, if this question has been answered, my apologies but i DID have a look around.
推荐答案
我不知道这是否是最好的方法,但这很简单:
I do not know if this is the best method, but it is quite easy:
// load an image
Image image = javax.imageio.ImageIO.read(new File("someimage.png");
// resize it
image = image.getScaledInstance(100, 100, Image.SCALE_SMOOTH);
// create a new image to render to
BufferedImage newimg = new BufferedImage(200,100,BufferedImage.TYPE_INT_ARGB);
// get graphics to draw..
Graphics2D graphics =newimg.createGraphics();
//draw the other image on it
graphics.drawImage(image,0,0,null);
graphics.drawImage(image,100,0,null);
graphics.fillOval(20,20,40,40); //making it a bit ugly ;)
//export the new image
ImageIO.write(newimg,"png",new File("output.png"));
//done!
为简单起见,我放弃了所有检查,异常处理等.
For simplicity I dropped all checks, exception handling, etc.
这篇关于使用Java进行图像处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!