Class Paths

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Paths()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.awt.image.BufferedImage applyClippingPath​(java.awt.Shape clip, java.awt.image.BufferedImage image)
      Applies the clipping path to the given image.
      static java.awt.image.BufferedImage applyClippingPath​(java.awt.Shape clip, java.awt.image.BufferedImage image, java.awt.image.BufferedImage destination)
      Applies the clipping path to the given image.
      private static java.lang.String arrayAsString​(byte[] bytes)  
      static void main​(java.lang.String[] args)  
      static java.awt.image.BufferedImage readClipped​(javax.imageio.stream.ImageInputStream stream)
      Reads the clipping path from the given input stream, if any, and applies it to the first image in the stream.
      private static int readMagic​(javax.imageio.stream.ImageInputStream stream)  
      static java.awt.geom.Path2D readPath​(javax.imageio.stream.ImageInputStream stream)
      Reads the clipping path from the given input stream, if any.
      private static java.awt.geom.Path2D readPathFromPhotoshopResources​(javax.imageio.stream.ImageInputStream stream)  
      static boolean writeClipped​(java.awt.image.RenderedImage image, java.awt.Shape clipPath, java.lang.String formatName, javax.imageio.stream.ImageOutputStream output)
      Writes the image along with a clipping path resource, in the given format, to the supplied output.
      • Methods inherited from class java.lang.Object

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

      • Paths

        private Paths()
    • Method Detail

      • readPath

        public static java.awt.geom.Path2D readPath​(javax.imageio.stream.ImageInputStream stream)
                                             throws java.io.IOException
        Reads the clipping path from the given input stream, if any. Supports PSD, JPEG and TIFF as container formats for Photoshop resources, or a "bare" PSD Image Resource Block.
        Parameters:
        stream - the input stream to read from, not null.
        Returns:
        the path, or null if no path is found
        Throws:
        java.io.IOException - if a general I/O exception occurs during reading.
        javax.imageio.IIOException - if the input contains a bad path data.
        java.lang.IllegalArgumentException - is stream is null.
        See Also:
        AdobePathReader
      • readMagic

        private static int readMagic​(javax.imageio.stream.ImageInputStream stream)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • readPathFromPhotoshopResources

        private static java.awt.geom.Path2D readPathFromPhotoshopResources​(javax.imageio.stream.ImageInputStream stream)
                                                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • applyClippingPath

        public static java.awt.image.BufferedImage applyClippingPath​(java.awt.Shape clip,
                                                                     java.awt.image.BufferedImage image)
        Applies the clipping path to the given image. All pixels outside the path will be transparent.
        Parameters:
        clip - the clipping path, not null
        image - the image to clip, not null
        Returns:
        the clipped image.
        Throws:
        java.lang.IllegalArgumentException - if clip or image is null.
      • applyClippingPath

        public static java.awt.image.BufferedImage applyClippingPath​(java.awt.Shape clip,
                                                                     java.awt.image.BufferedImage image,
                                                                     java.awt.image.BufferedImage destination)
        Applies the clipping path to the given image. Client code may decide the type of the destination image. The destination image is assumed to be fully transparent, and have same dimensions as image. All pixels outside the path will be transparent.
        Parameters:
        clip - the clipping path, not null.
        image - the image to clip, not null.
        destination - the destination image, may not be null or same instance as image.
        Returns:
        the clipped image.
        Throws:
        java.lang.IllegalArgumentException - if clip, image or destination is null, or if destination is the same instance as image.
      • readClipped

        public static java.awt.image.BufferedImage readClipped​(javax.imageio.stream.ImageInputStream stream)
                                                        throws java.io.IOException
        Reads the clipping path from the given input stream, if any, and applies it to the first image in the stream. If no path was found, the image is returned without any clipping. Supports PSD, JPEG and TIFF as container formats for Photoshop resources.
        Parameters:
        stream - the stream to read from, not null
        Returns:
        the clipped image
        Throws:
        java.io.IOException - if a general I/O exception occurs during reading.
        javax.imageio.IIOException - if the input contains a bad image or path data.
        java.lang.IllegalArgumentException - is stream is null.
      • writeClipped

        public static boolean writeClipped​(java.awt.image.RenderedImage image,
                                           java.awt.Shape clipPath,
                                           java.lang.String formatName,
                                           javax.imageio.stream.ImageOutputStream output)
                                    throws java.io.IOException
        Writes the image along with a clipping path resource, in the given format, to the supplied output. The image is written to the ImageOutputStream starting at the current stream pointer, overwriting existing stream data from that point forward, if present.

        Note: As ImageIO.write(RenderedImage, String, ImageOutputStream), this method does not close the output stream. It is the responsibility of the caller to close the stream, if desired.

        Implementation note: Only JPEG (using the "javax_imageio_jpeg_image_1.0" metadata format) and TIFF (using the "javax_imageio_tiff_image_1.0" or "com_sun_media_imageio_plugins_tiff_image_1.0" metadata formats) formats are currently supported.

        Parameters:
        image - the image to be written, may not be null.
        clipPath - the clip path, may not be null.
        formatName - the informal format name, may not be null.
        output - the stream to write to, may not be null.
        Returns:
        true if the image was written, otherwise false (ie. no writer was found for the specified format).
        Throws:
        java.lang.IllegalArgumentException - if any parameter is null.
        java.io.IOException - if an error occurs during writing.
      • arrayAsString

        private static java.lang.String arrayAsString​(byte[] bytes)
      • main

        public static void main​(java.lang.String[] args)
                         throws java.io.IOException,
                                java.lang.InterruptedException
        Throws:
        java.io.IOException
        java.lang.InterruptedException