繁体   English   中英

为什么我的代码只打印出该图像的一部分?

[英]Why is my code printing out only part of this image?

目前我从这篇文章中获取了代码: 合并两个图像

它工作正常! 但是,这就是我的图像发生的情况:组合部分没有完全渲染,但是,图像大小仍然合适。 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"));
}

}

找出原因,显然在主中有生成部分,同时还有框架和面板设置会导致它无法完全渲染。 我创建了一个用于生成图像的新方法,并创建了一个按钮来调用该方法,并且成功了!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM