0

2つの画像を重ねて描画しようとしています。1番目の画像は矢印です(最終的な画像ではヘッダーのように表示されます)。1番目の画像(矢印)は32x32ピクセルで、2番目の画像は24x24です。

理想的には、1番目の画像の右下隅から始めて、1番目の画像の上に2番目の画像を描画したいと思います。

現在、私はそのようなコードを使用しています

// load source images
        BufferedImage baseImage = ImageIO.read(new File(baseImg.getFileLocation()));
        BufferedImage backgroundImage = ImageIO.read(new File(backgroundImg.getFileLocation()));

        // create the new image, canvas size is the max. of both image sizes
        int w = Math.max(baseImage.getWidth(), backgroundImage.getWidth());
        int h = Math.max(baseImage.getHeight(), backgroundImage.getHeight());
        BufferedImage combined = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);

        // paint both images, preserving the alpha channels
        Graphics g = combined.getGraphics();
        g.drawImage(baseImage, 0, 0, null);
        g.drawImage(backgroundImage, 0, 0, null);

        int index = baseImg.getFileLocation().lastIndexOf(".png");
        String newFileName = baseImg.getFileLocation().substring(0, index);
        // Save as new image
        ImageIO.write(combined, "PNG", new File(newFileName + "_combined.png"));

しかし、最終的には32x32の画像になり、2番目の画像のみが描画されるため、これはうまくいきません。

どんな助けでも大歓迎です。

ありがとう !

4

1 に答える 1