0
我想绘制2个图像,一个在另一个之上。第1个图像是一个箭头(在最终图像中应该显示为标题)。第一个图像(箭头)是32x32像素,而第二个图像是24x24像素。绘制两个覆盖图像
理想情况下,我想从第1个图像的右下角开始在第1个顶部绘制第2个图像。
目前我使用这样的代码
// load source images
BufferedImage baseImage = ImageIO.read(new File(baseImg.getFileLocation()));
BufferedImage backgroundImage = ImageIO.read(new File(backgroundImg.getFileLocation()));
// create the new image, canvas size is the max. of both image sizes
int w = Math.max(baseImage.getWidth(), backgroundImage.getWidth());
int h = Math.max(baseImage.getHeight(), backgroundImage.getHeight());
BufferedImage combined = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
// paint both images, preserving the alpha channels
Graphics g = combined.getGraphics();
g.drawImage(baseImage, 0, 0, null);
g.drawImage(backgroundImage, 0, 0, null);
int index = baseImg.getFileLocation().lastIndexOf(".png");
String newFileName = baseImg.getFileLocation().substring(0, index);
// Save as new image
ImageIO.write(combined, "PNG", new File(newFileName + "_combined.png"));
但是这对我来说不是很的工作,因为最终的结果是与第二图象只被绘制的32×32的图像。
任何帮助表示赞赏。
谢谢!