#java.lang.IllegalArgumentException: Width (-1) and height (-1) cannot be <= 0

3 messages · Page 1 of 1 (latest)

shell ivy
#

Hi people! I suspect that my merge method is causing the error. Here is the method.

public static ImageIcon merge(ArrayList<ImageIcon> images, ArrayList<Float> transparency)
{
BufferedImage dest = null;
Graphics2D destG = null;
int rule; // This is SRC for the top image, and DST_OVER for the other ones
float alpha;

    for (int i = 0, size = images.size(); i < size; i++)
    {
        Image image = images.get(i).getImage();

        rule = AlphaComposite.SRC_OVER; // Default value
        alpha = transparency.get(i);

        if (i == 0)
        {
            dest = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
            destG = dest.createGraphics();

            rule = AlphaComposite.SRC; // Rule for 1st image
        }

        dest = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
        destG.setComposite(AlphaComposite.getInstance(rule, alpha));
        destG.drawImage(image, 0, 0, null);
    }

    return new ImageIcon(dest);
}
fallen kettleBOT
#

This post has been reserved for your question.

Hey @shell ivy! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.