Package com.twelvemonkeys.imageio.path
Class Paths
- java.lang.Object
-
- com.twelvemonkeys.imageio.path.Paths
-
public final class Paths extends java.lang.ObjectSupport for various Adobe Photoshop Path related operations:- Extract a path from an image input stream,
readPath(javax.imageio.stream.ImageInputStream) - Apply a given path to a given
BufferedImageapplyClippingPath(java.awt.Shape, java.awt.image.BufferedImage) - Read an image with path applied
readClipped(javax.imageio.stream.ImageInputStream) - Write an image with embedded path
writeClipped(java.awt.image.RenderedImage, java.awt.Shape, java.lang.String, javax.imageio.stream.ImageOutputStream)
- Version:
- $Id: Paths.java,v 1.0 08/12/14 harald.kuhr Exp$
- See Also:
- Adobe Photoshop Path resource format,
AdobePathReader
- Extract a path from an image input stream,
-
-
Constructor Summary
Constructors Modifier Constructor Description privatePaths()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.awt.image.BufferedImageapplyClippingPath(java.awt.Shape clip, java.awt.image.BufferedImage image)Applies the clipping path to the given image.static java.awt.image.BufferedImageapplyClippingPath(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.StringarrayAsString(byte[] bytes)static voidmain(java.lang.String[] args)static java.awt.image.BufferedImagereadClipped(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 intreadMagic(javax.imageio.stream.ImageInputStream stream)static java.awt.geom.Path2DreadPath(javax.imageio.stream.ImageInputStream stream)Reads the clipping path from the given input stream, if any.private static java.awt.geom.Path2DreadPathFromPhotoshopResources(javax.imageio.stream.ImageInputStream stream)static booleanwriteClipped(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.
-
-
-
Method Detail
-
readPath
public static java.awt.geom.Path2D readPath(javax.imageio.stream.ImageInputStream stream) throws java.io.IOExceptionReads 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:
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- isstreamisnull.- 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, notnullimage- the image to clip, notnull- Returns:
- the clipped image.
- Throws:
java.lang.IllegalArgumentException- ifcliporimageisnull.
-
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 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:
java.lang.IllegalArgumentException- ifclip,imageordestinationisnull, or ifdestinationis the same instance asimage.
-
readClipped
public static java.awt.image.BufferedImage readClipped(javax.imageio.stream.ImageInputStream stream) throws java.io.IOExceptionReads 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:
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- isstreamisnull.
-
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.IOExceptionWrites 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:
java.lang.IllegalArgumentException- if any parameter isnull.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.IOExceptionjava.lang.InterruptedException
-
-