Class Scaling

    • Constructor Detail

      • Scaling

        public Scaling()
    • Method Detail

      • scale

        public static void scale(BufferedImage source,
                                 BufferedImage dest)
        Scales the source image into the destination.
        Parameters:
        source - the source image.
        dest - the destination image. This must be smaller than the source image or an exception will be thrown. Also this need to be of type BufferedImage.TYPE_INT_ARGB.
      • scale

        public static BufferedImage scale(BufferedImage source,
                                          int w,
                                          int h)
        Scales the source image to a new, smaller size.
        Parameters:
        source - the source image.
        w - the new width. This must be less than the width of the source image, or an exception will be thrown.
        h - the new height. This must be less than the height of the source image, or an exception will be thrown.
        Returns:
        a new scaled image of type BufferedImage.TYPE_INT_ARGB.
      • scale

        public static BufferedImage scale(BufferedImage source,
                                          Dimension destSize)
        Scales the source image to a new, smaller size.
        Parameters:
        source - the source image.
        destSize - the size of the new image. This must be smaller than the size of the source image, or an exception will be thrown.
        Returns:
        a new scaled image of type BufferedImage.TYPE_INT_ARGB or BufferedImage.TYPE_INT_RGB.
      • scale

        public static BufferedImage scale(File source,
                                          int preferredType,
                                          Dimension destSize)
        Scales the source image file to a new, smaller size.
        Parameters:
        source - the source image file.
        preferredType - TYPE_INT_RGB, TYPE_INT_ARGB, TYPE_3BYTE_BGR, TYPE_4BYTE_ABGR.
        destSize - the size of the new image.
        Returns:
        a new scaled image of type BufferedImage.TYPE_INT_ARGB or BufferedImage.TYPE_INT_RGB.
      • scale

        public static BufferedImage scale(URL source,
                                          int preferredType,
                                          Dimension destSize)
        Scales the source image file to a new size.
        Parameters:
        source - the source image file.
        preferredType - TYPE_INT_RGB, TYPE_INT_ARGB, TYPE_3BYTE_BGR, TYPE_4BYTE_ABGR.
        destSize - the size of the new image.
        Returns:
        a new scaled image of type BufferedImage.TYPE_INT_ARGB or BufferedImage.TYPE_INT_RGB.
      • scale

        public static BufferedImage scale(BufferedImage source,
                                          BufferedImage dest,
                                          Dimension destSize)
        Scales the source image into the dest.
        Parameters:
        source - the source image. This may not be null.
        dest - the destination image. If non-null: this image must be at least destSize pixels in size or an exception will be thrown. If this is null: an image will be created that is destSize pixels.

        This argument can be the same as the source argument. This may save some memory allocation, but it will permanently alter the source image.

        Also this need to be of type BufferedImage.TYPE_INT_ARGB.

        destSize - the dimensions to write to. It is guaranteed that these pixels will be replaced in the dest image.
        Returns:
        the dest argument, or a new image if no dest argument was provided.
      • scale

        public static BufferedImage scale(Image source,
                                          BufferedImage dest,
                                          Dimension destSize)
        Scales the source image into the dest.
        Parameters:
        source - the source image. This may not be null.
        dest - the destination image. If non-null: this image must be at least destSize pixels in size or an exception will be thrown. If this is null: an image will be created that is destSize pixels.

        This argument can be the same as the source argument. This may save some memory allocation, but it will permanently alter the source image.

        Also this need to be of type BufferedImage.TYPE_INT_ARGB.

        destSize - the dimensions to write to. It is guaranteed that these pixels will be replaced in the dest image. If this is null then the image will not be scaled.
        Returns:
        the dest argument, or a new image if no dest argument was provided.
      • scaleProportionally

        public static BufferedImage scaleProportionally(BufferedImage image,
                                                        int maxWidth,
                                                        int maxHeight)
        Scales the source image proportionally to a new, smaller size.

        The new image will either have a width of maxWidth or a height of maxHeight (or both).

        Parameters:
        image - the source image to scale.
        maxWidth - the maximum width the scaled image can be.
        maxHeight - the maximum height the scaled image can be.
        Returns:
        a new scaled image.
      • scaleProportionally

        public static BufferedImage scaleProportionally(BufferedImage image,
                                                        Dimension maxSize)
        Scales the source image proportionally to a new, smaller size.

        The new image will either have a height of maxWidth or a height of maxHeight (or both).

        Parameters:
        image - the source image to scale.
        maxSize - the maximum dimensions the scaled image can be.
        Returns:
        a new scaled image.
      • scaleDimensionsProportionally

        public static Dimension scaleDimensionsProportionally(Dimension originalSize,
                                                              Dimension maxSize)
        This is a convenience method to calculate how to scale down an image proportionally.
        Parameters:
        originalSize - the original image dimensions.
        maxSize - the maximum new dimensions.
        Returns:
        dimensions that are maxSize or smaller.
      • scaleDimensionsProportionally

        public static Dimension2D scaleDimensionsProportionally(Dimension2D originalSize,
                                                                Dimension2D maxSize)
        This is a convenience method to calculate how to scale down an image proportionally.
        Parameters:
        originalSize - the original image dimensions.
        maxSize - the maximum new dimensions.
        Returns:
        dimensions that are maxSize or smaller.