Class ImageScaler

java.lang.Object
org.bzdev.imageio.ImageScaler

public class ImageScaler extends Object
Class for scaling images. The class supports various ways of specifying IO.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Get the height of the last image that was scaled.
    int
    Get the width of the last image that was scaled.
    scaleImage(int maxScaledWidth, int maxScaledHeight, Image image)
    Create a scaled buffered image file from an image.
    scaleImage(int maxScaledWidth, int maxScaledHeight, String inputFileName)
    Create a scaled buffered Image file given a file name for the input image.
    void
    scaleImage(int maxScaledWidth, int maxScaledHeight, String inputFileName, File outputFile, String type)
    Create a scaled image file given a file name for the input image and a file for the output image.
    void
    scaleImage(int maxScaledWidth, int maxScaledHeight, String inputFileName, OutputStream os, String type)
    Create a scaled image file given a file name for the input image and an output stream for the output image.
    void
    scaleImage(int maxScaledWidth, int maxScaledHeight, String inFileName, String outFileName, String type)
    Create a scaled image file given file names for the input and output images.
    scaleImage(int maxScaledWidth, int maxScaledHeight, URL url)
    Create a scaled buffered Image file given a URL for the input image.
    void
    scaleImage(int maxScaledWidth, int maxScaledHeight, URL url, File outputFile, String type)
    Create a scaled image file given a URL for the input image and a file for the output image.
    void
    scaleImage(int maxScaledWidth, int maxScaledHeight, URL url, OutputStream os, String type)
    Create a scaled image file given a URL for the input image and an output stream for the output image.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ImageScaler

      public ImageScaler()
      Constructor.
  • Method Details

    • scaleImage

      public void scaleImage(int maxScaledWidth, int maxScaledHeight, String inFileName, String outFileName, String type) throws IllegalArgumentException, IOException, InterruptedException
      Create a scaled image file given file names for the input and output images. The supported input file formats are those supported by Java. The image will not be distorted and will be as large as possible while fitting into a rectangle whose height and width are given by the arguments maxScaledWidth and maxScaledHeight respectively.

      If both maxScaledWdith and MaxScaledHeight are -1, they are set to 0.

      Parameters:
      maxScaledWidth - the maximum width of a scaled image in pixels; 0 for the image width and -1 if the width is not constrained
      maxScaledHeight - the maximum height of a scaled image in pixels; 0 for the image height and -1 if the height is not constrained
      inFileName - the name of the input file
      outFileName - the name of the output file
      type - the image type to create:
      Throws:
      IllegalArgumentException - generally an illegal input or output file name
      IOException - read or write operations failed
      InterruptedException - the current thread was interrupted
    • getLastImageWidth

      public int getLastImageWidth()
      Get the width of the last image that was scaled.
      Returns:
      the image width in pixels
    • getLastImageHeight

      public int getLastImageHeight()
      Get the height of the last image that was scaled.
      Returns:
      the image height in pixels
    • scaleImage

      public BufferedImage scaleImage(int maxScaledWidth, int maxScaledHeight, Image image) throws IllegalArgumentException, IOException, InterruptedException
      Create a scaled buffered image file from an image. The supported input file formats are those supported by Java. The image will not be distorted and will be as large as possible while fitting into a rectangle whose height and width are given by the arguments maxScaledWidth and maxScaledHeight respectively.

      If both maxScaledWdith and MaxScaledHeight are -1, they are set to 0.

      Parameters:
      maxScaledWidth - the maximum width of a scaled image in pixels; 0 for the image width and -1 if the width is not constrained
      maxScaledHeight - the maximum height of a scaled image in pixels; 0 for the image height and -1 if the height is not constrained
      image - the image to scale
      Returns:
      a scaled image
      Throws:
      IllegalArgumentException - generally an illegal input or output file name
      IOException - read or write operations failed
      InterruptedException - the current thread was interrupted
    • scaleImage

      public BufferedImage scaleImage(int maxScaledWidth, int maxScaledHeight, String inputFileName) throws IllegalArgumentException, IOException, InterruptedException
      Create a scaled buffered Image file given a file name for the input image. The supported input file formats are those supported by Java. The image will not be distorted and will be as large as possible while fitting into a rectangle whose height and width are given by the arguments maxScaledWidth and maxScaledHeight respectively.

      If both maxScaledWdith and MaxScaledHeight are -1, they are set to 0.

      Parameters:
      maxScaledWidth - the maximum width of a scaled image in pixels; 0 for the image width and -1 if the width is not constrained
      maxScaledHeight - the maximum height of a scaled image in pixels; 0 for the image height and -1 if the height is not constrained
      inputFileName - the name of the input file.
      Returns:
      a scaled image
      Throws:
      IllegalArgumentException - generally an illegal input or output file name
      IOException - read or write operations failed
      InterruptedException - the current thread was interrupted
    • scaleImage

      public BufferedImage scaleImage(int maxScaledWidth, int maxScaledHeight, URL url) throws IllegalArgumentException, IOException, InterruptedException
      Create a scaled buffered Image file given a URL for the input image. The supported input file formats are those supported by Java. The image will not be distorted and will be as large as possible while fitting into a rectangle whose height and width are given by the arguments maxScaledWidth and maxScaledHeight respectively.

      If both maxScaledWdith and MaxScaledHeight are -1, they are set to 0.

      Parameters:
      maxScaledWidth - the maximum width of a scaled image in pixels; 0 for the image width and -1 if the width is not constrained
      maxScaledHeight - the maximum height of a scaled image in pixels; 0 for the image height and -1 if the height is not constrained
      url - the URL of the input image
      Returns:
      a scaled image
      Throws:
      IllegalArgumentException - generally an illegal input or output file name
      IOException - read or write operations failed
      InterruptedException - the current thread was interrupted
    • scaleImage

      public void scaleImage(int maxScaledWidth, int maxScaledHeight, String inputFileName, File outputFile, String type) throws IllegalArgumentException, IOException, InterruptedException
      Create a scaled image file given a file name for the input image and a file for the output image. The supported input file formats are those supported by Java. The image will not be distorted and will be as large as possible while fitting into a rectangle whose height and width are given by the arguments maxScaledWidth and maxScaledHeight respectively.

      If both maxScaledWdith and MaxScaledHeight are -1, they are set to 0.

      Parameters:
      maxScaledWidth - the maximum width of a scaled image in pixels; 0 for the image width and -1 if the width is not constrained
      maxScaledHeight - the maximum height of a scaled image in pixels; 0 for the image height and -1 if the height is not constrained
      inputFileName - the name of the input file
      outputFile - the output file
      type - the image type to create:
      Throws:
      IllegalArgumentException - generally an illegal input or output file name
      IOException - read or write operations failed
      InterruptedException - the current thread was interrupted
    • scaleImage

      public void scaleImage(int maxScaledWidth, int maxScaledHeight, URL url, File outputFile, String type) throws IllegalArgumentException, IOException, InterruptedException
      Create a scaled image file given a URL for the input image and a file for the output image. The supported input file formats are those supported by Java. The image will not be distorted and will be as large as possible while fitting into a rectangle whose height and width are given by the arguments maxScaledWidth and maxScaledHeight respectively.

      If both maxScaledWdith and MaxScaledHeight are -1, they are set to 0.

      Parameters:
      maxScaledWidth - the maximum width of a scaled image in pixels; 0 for the image width and -1 if the width is not constrained
      maxScaledHeight - the maximum height of a scaled image in pixels; 0 for the image height and -1 if the height is not constrained
      url - the URL for the image source
      outputFile - the output file
      type - the image type to create:
      Throws:
      IllegalArgumentException - generally an illegal input or output file name
      IOException - read or write operations failed
      InterruptedException - the current thread was interrupted
    • scaleImage

      public void scaleImage(int maxScaledWidth, int maxScaledHeight, String inputFileName, OutputStream os, String type) throws IllegalArgumentException, IOException, InterruptedException
      Create a scaled image file given a file name for the input image and an output stream for the output image. The supported input file formats are those supported by Java. The image will not be distorted and will be as large as possible while fitting into a rectangle whose height and width are given by the arguments maxScaledWidth and maxScaledHeight respectively.

      If both maxScaledWdith and MaxScaledHeight are -1, they are set to 0.

      Parameters:
      maxScaledWidth - the maximum width of a scaled image in pixels; 0 for the image width and -1 if the width is not constrained
      maxScaledHeight - the maximum height of a scaled image in pixels; 0 for the image height and -1 if the height is not constrained
      inputFileName - the name of the input file
      os - the output stream
      type - the image type to create:
      Throws:
      IllegalArgumentException - generally an illegal input or output file name
      IOException - read or write operations failed
      InterruptedException - the current thread was interrupted
    • scaleImage

      public void scaleImage(int maxScaledWidth, int maxScaledHeight, URL url, OutputStream os, String type) throws IllegalArgumentException, IOException, InterruptedException
      Create a scaled image file given a URL for the input image and an output stream for the output image. The supported input file formats are those supported by Java.

      If both maxScaledWdith and MaxScaledHeight are -1, they are set to 0.

      Parameters:
      maxScaledWidth - the maximum width of a scaled image in pixels; 0 for the image width and -1 if the width is not constrained
      maxScaledHeight - the maximum height of a scaled image in pixels; 0 for the image height and -1 if the height is not constrained
      url - the URL for the image source
      os - the output stream
      type - the image type to create:
      Throws:
      IllegalArgumentException - generally an illegal input or output file name
      IOException - read or write operations failed
      InterruptedException - the current thread was interrupted