-1

Currently I took code from this post: Merging two images

And it works fine! However, this is what happens to my image: the combined part doesn't render fully, however, the image size is still proper. http://imgur.com/T6BlQLV

Any help is appreciated, thanks guys!

Lastly, here's my code:

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"));
}

}
Community
  • 1
  • 1

1 Answers1

-1

Found out why, apparently having the generating part in the main while also having the frame and panel setup causes it to not render fully. I made a new method for generating the image and made a button to call that method instead and it worked!

  • This solution makes no sense and isn't helpful to a future visitor unless you provide code and a description behind the logic of the fix. Ie. there is a known bug in component xy or you have to execute drawing code to the UI thread. – HopefullyHelpful Sep 17 '16 at 17:47