Class Paths

java.lang.Object
com.twelvemonkeys.imageio.path.Paths

public final class Paths extends Object
Support for various Adobe Photoshop Path related operations:
Version:
$Id: Paths.java,v 1.0 08/12/14 harald.kuhr Exp$
See Also:
  • Constructor Details

    • Paths

      private Paths()
  • Method Details

    • readPath

      public static Path2D readPath(ImageInputStream stream) throws 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:
      IOException - if a general I/O exception occurs during reading.
      IIOException - if the input contains a bad path data.
      IllegalArgumentException - is stream is null.
      See Also:
    • readMagic

      private static int readMagic(ImageInputStream stream) throws IOException
      Throws:
      IOException
    • readPathFromPhotoshopResources

      private static Path2D readPathFromPhotoshopResources(ImageInputStream stream) throws IOException
      Throws:
      IOException
    • applyClippingPath

      public static BufferedImage applyClippingPath(Shape clip, 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:
      IllegalArgumentException - if clip or image is null.
    • applyClippingPath

      public static BufferedImage applyClippingPath(Shape clip, BufferedImage 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:
      IllegalArgumentException - if clip, image or destination is null, or if destination is the same instance as image.
    • readClipped

      public static BufferedImage readClipped(ImageInputStream stream) throws 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:
      IOException - if a general I/O exception occurs during reading.
      IIOException - if the input contains a bad image or path data.
      IllegalArgumentException - is stream is null.
    • writeClipped

      public static boolean writeClipped(RenderedImage image, Shape clipPath, String formatName, ImageOutputStream output) throws 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:
      IllegalArgumentException - if any parameter is null.
      IOException - if an error occurs during writing.
    • arrayAsString

      private static String arrayAsString(byte[] bytes)
    • main

      public static void main(String[] args) throws IOException, InterruptedException
      Throws:
      IOException
      InterruptedException