Package com.twelvemonkeys.imageio.path
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(javax.imageio.stream.ImageInputStream)
- Apply a given path to a given
BufferedImage
applyClippingPath(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:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BufferedImage
applyClippingPath
(Shape clip, BufferedImage image) Applies the clipping path to the given image.static BufferedImage
applyClippingPath
(Shape clip, BufferedImage image, BufferedImage destination) Applies the clipping path to the given image.private static String
arrayAsString
(byte[] bytes) static void
static BufferedImage
readClipped
(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
(ImageInputStream stream) static Path2D
readPath
(ImageInputStream stream) Reads the clipping path from the given input stream, if any.private static Path2D
static boolean
writeClipped
(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
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
- isstream
isnull
.- 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, notnull
image
- the image to clip, notnull
- Returns:
- the clipped image.
- Throws:
IllegalArgumentException
- ifclip
orimage
isnull
.
-
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 thedestination
image. Thedestination
image 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 benull
or same instance asimage
.- Returns:
- the clipped image.
- Throws:
IllegalArgumentException
- ifclip
,image
ordestination
isnull
, or ifdestination
is 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
- isstream
isnull
.
-
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 theImageOutputStream
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 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:
true
if 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:
IOException
InterruptedException
-