How to save a BufferedImage as a File

后端 未结 6 1272
名媛妹妹
名媛妹妹 2020-11-29 20:16

I am using the imgscalr Java library to resize an image .

The result of a resize() method call is a BufferedImage object. I now want to save this as a file (usually

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-29 20:49

    1. Download and add imgscalr-lib-x.x.jar and imgscalr-lib-x.x-javadoc.jar to your Projects Libraries.
    2. In your code:

      import static org.imgscalr.Scalr.*;
      
      public static BufferedImage resizeBufferedImage(BufferedImage image, Scalr.Method scalrMethod, Scalr.Mode scalrMode, int width, int height)  {
          BufferedImage bi = image;
          bi = resize( image, scalrMethod, scalrMode, width, height);
      return bi;
      }
      
      // Save image:
      ImageIO.write(Scalr.resize(etotBImage, 150), "jpg", new File(myDir));
      

提交回复
热议问题