JPEG 이미지를 통해 두 이미지의 PNG/TIFF 파일을 병합하려고합니다. 다음 코드2 개의 이미지 중첩이 제대로 작동하지 않습니다.
try {
image = ImageIO.read(new File("C:\\Users\\user\\Desktop\\test\\a.jpg"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
BufferedImage overlay = null;
try {
overlay = ImageIO.read(new File("C:\\Users\\user\\Desktop\\test\\b.png"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// create the new image, canvas size is the max. of both image sizes
int w = Math.max(image.getWidth(), overlay.getWidth());
int h = Math.max(image.getHeight(), overlay.getHeight());
BufferedImage combined = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
// paint both images, preserving the alpha channels
Graphics2D g = combined.createGraphics();
/**Set Antialias Rendering**/
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
/**
* Draw background image at location (0,0)
* You can change the (x,y) value as required
*/
g.drawImage(image, 0, 0, null);
/**
* Draw foreground image at location (0,0)
* Change (x,y) value as required.
*/
g.drawImage(overlay, 0, 0, null);
g.dispose();
// Save as new image
try {
ImageIO.write(combined, "JPG", new File("C:\\Users\\user\\Desktop\\test\\c.jpg"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
하지만, 내가 원하는 내용에 따라되지 형성되어 다음 최종 이미지를 사용하고 있습니다. 명확성을 위해 첨부 된 이미지를 참조하십시오. 당신이 아래에있는 이미지를 볼 수 있도록
PNG 이미지 는 투명한 배경이 있어야합니다. 그거야? – Joni
1) 더 빨리 도움을 받으려면 [SSCCE] (http://sscce.org/)를 게시하십시오. 2) 작은 이미지를 사용하십시오. 3) 3 번째 이미지는 처음 2 개의 이미지를 결합한 결과입니까? –
1) 이것은 코드입니다 2)이 코드는 JPEG와 PNG/TIFF가 아닌 두 개의 PNG 파일과 함께 작동합니다. 3) 예 .. is is .. – ItachiUchiha