Class ScaleImageOperation

  • All Implemented Interfaces:
    ImageOperation
    Direct Known Subclasses:
    CropAndScaleImageOperation

    public class ScaleImageOperation
    extends AbstractScaleImageOperation

    Creates a scaled version of an image. The given scaling parameters define a bounding box with a certain width and height. Images that do not fit in this box (i.e. are too large) are always scaled down such that they do fit. If the aspect ratio of the original image differs from that of the bounding box, either the width or the height of scaled image will be less than that of the box.

    Unless of course cropping is set to true, then the original images is cropped to fill the bounding box.

    Smaller images are scaled up in the same way as large images are scaled down, but only if upscaling is true. When upscaling is false and the image is smaller than the bounding box, the scaled image will be equal to the original.

    If the width or height of the scaling parameters is 0 or less, that side of the bounding box does not exist (i.e. is unbounded). If both sides of the bounding box are unbounded, the scaled image will be equal to the original.

    • Constructor Detail

      • ScaleImageOperation

        public ScaleImageOperation​(ScalingParameters parameters)
        Creates a scaling operation from a complete set of scaling parameters.
        Parameters:
        parameters - the parameters to use for the scaling
      • ScaleImageOperation

        @Deprecated
        public ScaleImageOperation​(int width,
                                   int height,
                                   boolean upscaling)
        Deprecated.
        Creates a image scaling operation, defined by the bounding box of a certain width and height. The strategy will be set to ImageUtils.ScalingStrategy.QUALITY, and the maximum memory usage to zero (i.e. undefined).
        Parameters:
        width - the width of the bounding box in pixels
        height - the height of the bounding box in pixels
        upscaling - whether to enlarge images that are smaller than the bounding box
      • ScaleImageOperation

        @Deprecated
        public ScaleImageOperation​(int width,
                                   int height,
                                   boolean upscaling,
                                   ImageUtils.ScalingStrategy strategy)
        Deprecated.
        Creates a image scaling operation, defined by the bounding box of a certain width and height.
        Parameters:
        width - the width of the bounding box in pixels
        height - the height of the bounding box in pixels
        upscaling - whether to enlarge images that are smaller than the bounding box
        strategy - the strategy to use for scaling the image (e.g. optimize for speed, quality, a trade-off between these two, etc.)
      • ScaleImageOperation

        @Deprecated
        public ScaleImageOperation​(int width,
                                   int height,
                                   boolean upscaling,
                                   ImageUtils.ScalingStrategy strategy,
                                   float compressionQuality)
        Deprecated.
        Creates a image scaling operation, defined by the bounding box of a certain width and height.
        Parameters:
        width - the width of the bounding box in pixels
        height - the height of the bounding box in pixels
        upscaling - whether to enlarge images that are smaller than the bounding box
        strategy - the strategy to use for scaling the image (e.g. optimize for speed, quality, a trade-off between these two, etc.)
        compressionQuality - a float between 0 and 1 indicating the compression quality to use for writing the scaled image data.
      • ScaleImageOperation

        @Deprecated
        public ScaleImageOperation​(int width,
                                   int height,
                                   boolean upscaling,
                                   boolean cropping,
                                   ImageUtils.ScalingStrategy strategy,
                                   float compressionQuality)
        Deprecated.
        Creates a image scaling operation, defined by the bounding box of a certain width and height.
        Parameters:
        width - the width of the bounding box in pixels
        height - the height of the bounding box in pixels
        upscaling - whether to enlarge images that are smaller than the bounding box
        cropping - whether to crop to original to fill the bounding box
        strategy - the strategy to use for scaling the image (e.g. optimize for speed, quality, a trade-off between these two, etc.)
        compressionQuality - a float between 0 and 1 indicating the compression quality to use for writing the scaled image data.
    • Method Detail

      • execute

        public void execute​(InputStream data,
                            ImageReader reader,
                            ImageWriter writer)
                     throws IOException
        Creates a scaled version of an image. The given scaling parameters define a bounding box with a certain width and height. Images that do not fit in this box (i.e. are too large) are always scaled down such that they do fit. If the aspect ratio of the original image differs from that of the bounding box, either the width or the height of scaled image will be less than that of the box.

        Smaller images are scaled up in the same way as large images are scaled down, but only if upscaling is true. When upscaling is false and the image is smaller than the bounding box, the scaled image will be equal to the original.

        If the width or height of the scaling parameters is 0 or less, that side of the bounding box does not exist (i.e. is unbounded). If both sides of the bounding box are unbounded, the scaled image will be equal to the original.

        Specified by:
        execute in class AbstractImageOperation
        Parameters:
        data - the original image data
        reader - reader for the image data
        writer - writer for the image data
        Throws:
        IOException - when the image operation fails