How to blend two image

前端 未结 1 1265
花落未央
花落未央 2020-12-04 01:12

I want to blend two images together with a ratio of 4:1

the result should be something like this

\"ent

相关标签:
1条回答
  • 2020-12-04 02:00

    The question is vague, but you could use the 2D Graphics API

    Take a look at 2D Graphics and Compositing Graphics in particular...

    So using the following images (base on left, overlay on right)

    BaseOverlay

    try {
        BufferedImage base = ImageIO.read(new File("base.jpg"));
        BufferedImage overlay = ImageIO.read(new File("overlay.jpg"));
    
        Graphics2D g2d = base.createGraphics();
        g2d.setComposite(AlphaComposite.SrcOver.derive(0.5f));
        int x = (base.getWidth() - overlay.getWidth()) / 2;
        int y = (base.getHeight() - overlay.getHeight()) / 2;
        g2d.drawImage(overlay, x, y, null);
        g2d.dispose();
    
        ImageIO.write(base, "jpg", new File("Blended.jpg"));
    } catch (IOException e) {
        e.printStackTrace();
    }
    

    Resulting in...

    Blending

    Take a look at...

    • Reading/Loading an Image
    • Writing/Saving an Image

    for more details...

    0 讨论(0)
提交回复
热议问题