public interface Image extends Bounded
Page
.Page.getImages()
Modifier and Type | Interface and Description |
---|---|
static class |
Image.Format
An enumeration of the different formats in which
image data may be produced,
as indicated by Image.dataFormat() . |
Modifier and Type | Method and Description |
---|---|
java.awt.image.BufferedImage |
bitmap()
Returns a
BufferedImage for this Image that is ready to be drawn to a graphics context. |
Region |
bitmapBounds()
Returns a
Region whose width and height indicate that of the bitmap itself;
its origin coordinates (Region.lx() and Region.by() ) will always be
0, 0 . |
byte[] |
data()
Returns the data for this image, encoded according to the format
indicated by
Image.dataFormat() ; may return null if it is known that the image's
data cannot be decoded without producing an exception. |
Image.Format |
dataFormat()
Returns the format of the image data available from this image's
Image.data() method. |
java.lang.String |
id()
Returns the identifier associated with this image's bitmap data, guaranteed to be unique within the
scope of its source document.
|
java.awt.image.BufferedImage bitmap()
BufferedImage
for this Image
that is ready to be drawn to a graphics context.
This method may return null
if it is known that the image's
data cannot be decoded without producing an exception, or if the image's
Image.dataFormat()
is JPX / JPEG2000
.
BufferedImage
object returned from this method provides a .getBitmap()
method that efficiently produces a .NET System.Drawing.Bitmap
object. So, the pattern
you'd typically use with Image.bitmap()
is e.g.:
Page page = pdf.getPage(0); Image image = page.getImages().get(0).bitmap(); if (image != null) { System.Drawing.Bitmap bmp = image.getBitmap(); // ...code continues... }
Region bitmapBounds()
Region
whose width and height indicate that of the bitmap itself;
its origin coordinates (Region.lx()
and Region.by()
) will always be
0, 0
.
This does not represent the apparent bounds of the image when positioned
on the page; use Bounded.bounds()
for that.
byte[] data()
Image.dataFormat()
; may return null
if it is known that the image's
data cannot be decoded without producing an exception.Image.Format dataFormat()
Image.data()
method.java.lang.String id()
PDF documents can display the same bitmap multiple times; for example, an image that appears in the header
of every page is very likely to be encoded once, and then just referenced at each point of usage. Though
PDFxStream produces an different Image
instance for each image shown in a PDF document, it:
id
Image.bitmap()
and
Image.data()
are called
Together, this means that you can access all of the Image
s on a page or in a document, and
gain easy, efficient access to their apparent Bounded.bounds()
on the page, but then never
decode the same bitmap data more than once: just track each Image
's id
, and reuse the
Image.data()
or Image.bitmap()
objects for any duplicate id
s you find.