java.lang.Object
one.jpro.platform.image.manager.encoder.ImageEncoderJPG
All Implemented Interfaces:
ImageEncoder, JsonConvertible

public class ImageEncoderJPG extends Object implements ImageEncoder
An implementation of ImageEncoder for encoding images in JPG format.
See Also:
  • Constructor Details

    • ImageEncoderJPG

      public ImageEncoderJPG()
      Default constructor. Initializes with a default quality of 0.80.
    • ImageEncoderJPG

      public ImageEncoderJPG(double quality)
      Constructor with specified quality.
      Parameters:
      quality - The quality factor for encoding, a value between 0.0 and 1.0.
      Throws:
      IllegalArgumentException - If the provided quality is not between 0.0 and 1.0.
  • Method Details

    • saveImage

      public void saveImage(BufferedImage image, File target)
      Save the provided image to the specified file in JPG format. Note: The current implementation doesn't consider the quality settings due to Java's ImageIO limitations.
      Specified by:
      saveImage in interface ImageEncoder
      Parameters:
      image - The image to be saved.
      target - The target file where the image will be saved.
      Throws:
      ImageEncoderException - If there's an error while saving the image.
    • getFileExtension

      public String getFileExtension()
      Gets the file extension for this encoder, which is "jpg".
      Specified by:
      getFileExtension in interface ImageEncoder
      Returns:
      The file extension string.
    • toJSON

      public org.json.JSONObject toJSON()
      Description copied from interface: JsonConvertible
      Converts the object to a JSON representation.
      Specified by:
      toJSON in interface JsonConvertible
      Returns:
      A JSONObject representing the object.