Class SampledImageReader
java.lang.Object
org.apache.pdfbox.pdmodel.graphics.image.SampledImageReader
Reads a sampled image from a PDF file.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static BufferedImage
applyColorKeyMask
(BufferedImage image, BufferedImage mask) private static Rectangle
clipRegion
(PDImage pdImage, Rectangle region) private static BufferedImage
private static BufferedImage
from8bit
(PDImage pdImage, WritableRaster raster, Rectangle clipped, int subsampling, int width, int height) private static BufferedImage
fromAny
(PDImage pdImage, WritableRaster raster, COSArray colorKey, Rectangle clipped, int subsampling, int width, int height) private static float[]
getDecodeArray
(PDImage pdImage) static WritableRaster
getRawRaster
(PDImage pdImage) Extract the raw unconverted raster of the given imagestatic BufferedImage
getRGBImage
(PDImage pdImage, Rectangle region, int subsampling, COSArray colorKey) Returns the content of the given image as a newly created AWT buffered image with an RGB color space.static BufferedImage
getRGBImage
(PDImage pdImage, COSArray colorKey) Returns the content of the given image as an AWT buffered image with an RGB color space.static BufferedImage
getStencilImage
(PDImage pdImage, 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, WritableRaster raster)
-
Field Details
-
LOG
private static final org.apache.commons.logging.Log LOG
-
-
Constructor Details
-
SampledImageReader
private SampledImageReader()
-
-
Method Details
-
getStencilImage
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:
IOException
- if the image cannot be readIllegalStateException
- if the image is not a stencil.
-
getRGBImage
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:
IOException
- if the image cannot be read
-
clipRegion
-
getRGBImage
public static BufferedImage getRGBImage(PDImage pdImage, Rectangle region, int subsampling, COSArray colorKey) throws IOException Returns the content of the given image as a newly created 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:
IOException
- if the image cannot be read
-
getRawRaster
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:
IOException
-
readRasterFromAny
- Throws:
IOException
-
from1Bit
private static BufferedImage from1Bit(PDImage pdImage, Rectangle clipped, int subsampling, int width, int height) throws IOException - Throws:
IOException
-
from8bit
private static BufferedImage from8bit(PDImage pdImage, WritableRaster raster, Rectangle clipped, int subsampling, int width, int height) throws IOException - Throws:
IOException
-
fromAny
private static BufferedImage fromAny(PDImage pdImage, WritableRaster raster, COSArray colorKey, Rectangle clipped, int subsampling, int width, int height) throws IOException - Throws:
IOException
-
applyColorKeyMask
-
getDecodeArray
- Throws:
IOException
-