Java ARGB to JPG

后端 未结 2 754
灰色年华
灰色年华 2020-12-19 20:08

How can I save BufferedImage with TYPE_INT_ARGB to jpg?

Program generates me that image:

2条回答
  •  既然无缘
    2020-12-19 20:33

    OK! I've solved it. Everything was pretty easy. Don't know is it a good decision and how fast it is. I have not found any other. So.. everything we need is define new BufferedImage.

    BufferedImage buffImg = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = buffImg.createGraphics();
    
    // ... other code we need
    
    BufferedImage img= new BufferedImage(buffImg.getWidth(), buffImg.getHeight(), BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = img.createGraphics();
    g2d.drawImage(buffImg, 0, 0, null);
    g2d.dispose();
    

    If there any ideas to improve this method, please, your welcome.

提交回复
热议问题