Class SampledImageReader
- java.lang.Object
-
- org.apache.pdfbox.pdmodel.graphics.image.SampledImageReader
-
final class SampledImageReader extends java.lang.Object
Reads a sampled image from a PDF file.
-
-
Field Summary
Fields Modifier and Type Field Description private static org.apache.commons.logging.Log
LOG
-
Constructor Summary
Constructors Modifier Constructor Description private
SampledImageReader()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static java.awt.image.BufferedImage
applyColorKeyMask(java.awt.image.BufferedImage image, java.awt.image.BufferedImage mask)
private static java.awt.Rectangle
clipRegion(PDImage pdImage, java.awt.Rectangle region)
private static java.awt.image.BufferedImage
from1Bit(PDImage pdImage, java.awt.Rectangle clipped, int subsampling, int width, int height)
private static java.awt.image.BufferedImage
from8bit(PDImage pdImage, java.awt.image.WritableRaster raster, java.awt.Rectangle clipped, int subsampling, int width, int height)
private static java.awt.image.BufferedImage
fromAny(PDImage pdImage, java.awt.image.WritableRaster raster, COSArray colorKey, java.awt.Rectangle clipped, int subsampling, int width, int height)
private static float[]
getDecodeArray(PDImage pdImage)
static java.awt.image.WritableRaster
getRawRaster(PDImage pdImage)
Extract the raw unconverted raster of the given imagestatic java.awt.image.BufferedImage
getRGBImage(PDImage pdImage, java.awt.Rectangle region, int subsampling, COSArray colorKey)
Returns the content of the given image as an AWT buffered image with an RGB color space.static java.awt.image.BufferedImage
getRGBImage(PDImage pdImage, COSArray colorKey)
Returns the content of the given image as an AWT buffered image with an RGB color space.static java.awt.image.BufferedImage
getStencilImage(PDImage pdImage, java.awt.Paint paint)
Returns an ARGB image filled with the given paint and using the given image as a mask.private static void
readRasterFromAny(PDImage pdImage, java.awt.image.WritableRaster raster)
-
-
-
Method Detail
-
getStencilImage
public static java.awt.image.BufferedImage getStencilImage(PDImage pdImage, java.awt.Paint paint) throws java.io.IOException
Returns an ARGB image filled with the given paint and using the given image as a mask.- Parameters:
paint
- the paint to fill the visible portions of the image with- Returns:
- a masked image filled with the given paint
- Throws:
java.io.IOException
- if the image cannot be readjava.lang.IllegalStateException
- if the image is not a stencil.
-
getRGBImage
public static java.awt.image.BufferedImage getRGBImage(PDImage pdImage, COSArray colorKey) throws java.io.IOException
Returns the content of the given image as an AWT buffered image with an RGB color space. If a color key mask is provided then an ARGB image is returned instead. This method never returns null.- Parameters:
pdImage
- the image to readcolorKey
- an optional color key mask- Returns:
- content of this image as an RGB buffered image
- Throws:
java.io.IOException
- if the image cannot be read
-
clipRegion
private static java.awt.Rectangle clipRegion(PDImage pdImage, java.awt.Rectangle region)
-
getRGBImage
public static java.awt.image.BufferedImage getRGBImage(PDImage pdImage, java.awt.Rectangle region, int subsampling, COSArray colorKey) throws java.io.IOException
Returns the content of the given image as an AWT buffered image with an RGB color space. If a color key mask is provided then an ARGB image is returned instead. This method never returns null.- Parameters:
pdImage
- the image to readregion
- The region of the source image to get, or null if the entire image is needed. The actual region will be clipped to the dimensions of the source image.subsampling
- The amount of rows and columns to advance for every output pixel, a value of 1 meaning every pixel will be read. It must not be larger than the image width or height.colorKey
- an optional color key mask- Returns:
- content of this image as an (A)RGB buffered image
- Throws:
java.io.IOException
- if the image cannot be read
-
getRawRaster
public static java.awt.image.WritableRaster getRawRaster(PDImage pdImage) throws java.io.IOException
Extract the raw unconverted raster of the given image- Parameters:
pdImage
- The image to get the raw raster data from- Returns:
- the raw raster of this image
- Throws:
java.io.IOException
-
readRasterFromAny
private static void readRasterFromAny(PDImage pdImage, java.awt.image.WritableRaster raster) throws java.io.IOException
- Throws:
java.io.IOException
-
from1Bit
private static java.awt.image.BufferedImage from1Bit(PDImage pdImage, java.awt.Rectangle clipped, int subsampling, int width, int height) throws java.io.IOException
- Throws:
java.io.IOException
-
from8bit
private static java.awt.image.BufferedImage from8bit(PDImage pdImage, java.awt.image.WritableRaster raster, java.awt.Rectangle clipped, int subsampling, int width, int height) throws java.io.IOException
- Throws:
java.io.IOException
-
fromAny
private static java.awt.image.BufferedImage fromAny(PDImage pdImage, java.awt.image.WritableRaster raster, COSArray colorKey, java.awt.Rectangle clipped, int subsampling, int width, int height) throws java.io.IOException
- Throws:
java.io.IOException
-
applyColorKeyMask
private static java.awt.image.BufferedImage applyColorKeyMask(java.awt.image.BufferedImage image, java.awt.image.BufferedImage mask)
-
getDecodeArray
private static float[] getDecodeArray(PDImage pdImage) throws java.io.IOException
- Throws:
java.io.IOException
-
-