Class Paths
java.lang.Object
com.twelvemonkeys.imageio.path.Paths
Support for various Adobe Photoshop Path related operations:
- Extract a path from an image input stream,
readPath(ImageInputStream) - Apply a given path to a given
BufferedImageapplyClippingPath(Shape, BufferedImage) - Read an image with path applied
readClipped(ImageInputStream) - Write an image with embedded path
writeClipped(RenderedImage, Shape, String, ImageOutputStream)
- Version:
- $Id: Paths.java,v 1.0 08/12/14 harald.kuhr Exp$
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BufferedImageapplyClippingPath(Shape clip, BufferedImage image) Applies the clipping path to the given image.static BufferedImageapplyClippingPath(Shape clip, BufferedImage image, BufferedImage destination) Applies the clipping path to the given image.private static StringarrayAsString(byte[] bytes) static voidstatic BufferedImagereadClipped(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 intreadMagic(ImageInputStream stream) static Path2DreadPath(ImageInputStream stream) Reads the clipping path from the given input stream, if any.private static Path2Dstatic booleanwriteClipped(RenderedImage image, Shape clipPath, String formatName, ImageOutputStream output) Writes the image along with a clipping path resource, in the given format, to the supplied output.
-
Constructor Details
-
Paths
private Paths()
-
-
Method Details
-
readPath
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, notnull.- Returns:
- the path, or
nullif 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- isstreamisnull.- See Also:
-
readMagic
- Throws:
IOException
-
readPathFromPhotoshopResources
- Throws:
IOException
-
applyClippingPath
Applies the clipping path to the given image. All pixels outside the path will be transparent.- Parameters:
clip- the clipping path, notnullimage- the image to clip, notnull- Returns:
- the clipped image.
- Throws:
IllegalArgumentException- ifcliporimageisnull.
-
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 thedestinationimage. Thedestinationimage is assumed to be fully transparent, and have same dimensions asimage. All pixels outside the path will be transparent.- Parameters:
clip- the clipping path, notnull.image- the image to clip, notnull.destination- the destination image, may not benullor same instance asimage.- Returns:
- the clipped image.
- Throws:
IllegalArgumentException- ifclip,imageordestinationisnull, or ifdestinationis the same instance asimage.
-
readClipped
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, notnull- 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- isstreamisnull.
-
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 theImageOutputStreamstarting 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 benull.clipPath- the clip path, may not benull.formatName- the informal format name, may not benull.output- the stream to write to, may not benull.- Returns:
trueif the image was written, otherwisefalse(ie. no writer was found for the specified format).- Throws:
IllegalArgumentException- if any parameter isnull.IOException- if an error occurs during writing.
-
arrayAsString
-
main
- Throws:
IOExceptionInterruptedException
-