Class Canvas

  • All Implemented Interfaces:
    ImageFilter

    public class Canvas
    extends java.lang.Object
    implements ImageFilter
    An ImageFilter which will enclose an image into a specified enclosing image.

    The intended use of this ImageFilter is to take an image and place it inside of a larger image, creating a border around the original image. This can be useful when the dimensions of a thumbnail must always be the same dimensions, and the original images are of differing dimensions.

    The fill color used for the enclosing image can be specified, along with whether or not to crop an image if it is larger than the enclosing image.

    Since:
    0.3.2
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private boolean crop
      Whether or not to crop the enclosed image if the enclosing image is smaller than the enclosed image.
      private java.awt.Color fillColor
      The fill color for the background.
      private int height
      The width of the enclosing image.
      private Position position
      The positioning of the enclosed image.
      private int width
      The width of the enclosing image.
    • Constructor Summary

      Constructors 
      Constructor Description
      Canvas​(int width, int height, Position position)
      Instantiates a Canvas filter.
      Canvas​(int width, int height, Position position, boolean crop)
      Instantiates a Canvas filter.
      Canvas​(int width, int height, Position position, boolean crop, java.awt.Color fillColor)
      Instantiates a Canvas filter.
      Canvas​(int width, int height, Position position, java.awt.Color fillColor)
      Instantiates a Canvas filter.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.awt.image.BufferedImage apply​(java.awt.image.BufferedImage img)
      Applies a image filtering operation on an image.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • width

        private final int width
        The width of the enclosing image.
      • height

        private final int height
        The width of the enclosing image.
      • position

        private final Position position
        The positioning of the enclosed image.
      • fillColor

        private final java.awt.Color fillColor
        The fill color for the background.
      • crop

        private final boolean crop
        Whether or not to crop the enclosed image if the enclosing image is smaller than the enclosed image.
    • Constructor Detail

      • Canvas

        public Canvas​(int width,
                      int height,
                      Position position)
        Instantiates a Canvas filter.

        No fill color will be applied to the filtered image. If the image to filter does not have a transparency channel, the image will be filled black.

        Crops the enclosed image if the enclosing image is smaller.

        Parameters:
        width - The width of the filtered image.
        height - The height of the filtered image.
        position - The position to place the enclosed image.
      • Canvas

        public Canvas​(int width,
                      int height,
                      Position position,
                      boolean crop)
        Instantiates a Canvas filter.

        No fill color will be applied to the filtered image. If the image to filter does not have a transparency channel, the image will be filled black.

        Parameters:
        width - The width of the filtered image.
        height - The height of the filtered image.
        position - The position to place the enclosed image.
        crop - Whether or not to crop the enclosed image if the enclosed image has dimensions which are larger than the specified width and height.
      • Canvas

        public Canvas​(int width,
                      int height,
                      Position position,
                      java.awt.Color fillColor)
        Instantiates a Canvas filter.

        Crops the enclosed image if the enclosing image is smaller.

        Parameters:
        width - The width of the filtered image.
        height - The height of the filtered image.
        position - The position to place the enclosed image.
        fillColor - The color to fill portions of the image which is not covered by the enclosed image. Portions of the image which is transparent will be filled with the specified color as well.
      • Canvas

        public Canvas​(int width,
                      int height,
                      Position position,
                      boolean crop,
                      java.awt.Color fillColor)
        Instantiates a Canvas filter.
        Parameters:
        width - The width of the filtered image.
        height - The height of the filtered image.
        position - The position to place the enclosed image.
        crop - Whether or not to crop the enclosed image if the enclosed image has dimensions which are larger than the specified width and height.
        fillColor - The color to fill portions of the image which is not covered by the enclosed image. Portions of the image which is transparent will be filled with the specified color as well.
    • Method Detail

      • apply

        public java.awt.image.BufferedImage apply​(java.awt.image.BufferedImage img)
        Description copied from interface: ImageFilter
        Applies a image filtering operation on an image.
        Specified by:
        apply in interface ImageFilter
        Parameters:
        img - The image to apply the filtering on.
        Returns:
        The resulting image after applying this filter.