-1
目前我採取了這篇文章的代碼:Merging two images爲什麼我的代碼僅打印此圖像的一部分?
它工作正常!但是,這是我的圖像發生的情況:組合部分不完全渲染,但是,圖像大小仍然正確。 http://imgur.com/T6BlQLV
任何幫助表示讚賞,謝謝你們!
最後,這裏是我的代碼:
public class CAATemplate extends JPanel {
final static int frameWidth = 500;
final static int frameHeight = 500;
static JLabel descBackground = new JLabel("Background Type:");
static JButton make = new JButton("Generate");
static String bgPath = "Images/Backgrounds/"; // base path of the images
static String miPath = "Images/MainIcons/";
static String opPath = "Output/";
static BufferedImage image;
public void CAATemplate() {
}
public void paint(Graphics g) {
g.drawImage(image, 0, 0, Color.gray, this);
}
public static void main(String[] args) throws IOException {
JFrame frame = new JFrame();
JPanel p = new JPanel();
p.add(descBackground);
p.add(make);
frame.add(p);
frame.setBackground(Color.gray);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(frameWidth, frameHeight);
frame.setVisible(true);
frame.setLocation(200, 100);
// load source images
image = ImageIO.read(new File(bgPath + "RedBackground1.png"));
BufferedImage overlay = ImageIO.read(new File(miPath + "Mooncakes.png"));
// create the new image, canvas size is the max. of both image sizes
int w = 2750;
int h = 2125;
BufferedImage combined = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
// paint both images, preserving the alpha channels
Graphics g = combined.getGraphics();
g.drawImage(image, 0, 0, null);
g.drawImage(overlay, 437, 1483, null);
// Save as new image
ImageIO.write(combined, "png", new File(opPath + "combined.png"));
}
}
此解決方案沒有意義,對未來的訪問者沒有幫助,除非您在修補程序的邏輯背後提供代碼和說明。 IE瀏覽器。在組件xy中有一個已知的錯誤,或者您必須執行到UI線程的繪圖代碼。 – HopefullyHelpful