Module bus.extra

Class ImageWriter

java.lang.Object
org.miaixz.bus.extra.image.ImageWriter
All Implemented Interfaces:
Flushable

public class ImageWriter extends Object implements Flushable
Image writer wrapper.
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • ImageWriter

      public ImageWriter(Image image, String imageType)
      Constructor.
      Parameters:
      image - The Image.
      imageType - The image type (extension), or null for RGB mode (JPG).
  • Method Details

    • of

      public static ImageWriter of(Image image, String imageType, Color backgroundColor)
      Creates an ImageWriter.
      Parameters:
      image - The image.
      imageType - The image type (extension), or null for RGB mode (JPG).
      backgroundColor - The background color Color, or null for black or transparent.
      Returns:
      An ImageWriter.
    • of

      public static ImageWriter of(Image image, String imageType)
      Creates an ImageWriter.
      Parameters:
      image - The image.
      imageType - The image type (extension), or null for RGB mode (JPG).
      Returns:
      An ImageWriter.
    • setQuality

      public ImageWriter setQuality(float quality)
      Sets the write quality. A value between 0 and 1 (exclusive) indicates a compression ratio; other values indicate no compression.
      Parameters:
      quality - The write quality, a value between 0 and 1 (exclusive) for compression.
      Returns:
      this
    • write

      public void write(OutputStream out) throws org.miaixz.bus.core.lang.exception.InternalException
      Writes the image. This method does not close the stream.
      Parameters:
      out - The target output stream.
      Throws:
      org.miaixz.bus.core.lang.exception.InternalException - if an I/O error occurs.
    • write

      public void write(File destFile) throws org.miaixz.bus.core.lang.exception.InternalException
      Writes the image in the format corresponding to the destination file's extension.
      Parameters:
      destFile - The destination file.
      Throws:
      org.miaixz.bus.core.lang.exception.InternalException - if an I/O error occurs.
    • write

      public void write(ImageOutputStream output)
      Writes the image to an output stream using an ImageWriter.
      Parameters:
      output - The ImageOutputStream to write to (not null).
    • flush

      public void flush()
      Specified by:
      flush in interface Flushable