Interface Image
-
- All Superinterfaces:
Bounded
public interface Image extends Bounded
Represents an image found in aPage
.- Since:
- v3.0
- Version:
- ©2004-2024 Snowtide
- See Also:
Page.getImages()
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
Image.Format
An enumeration of the different formats in whichimage data
may be produced, as indicated bydataFormat()
.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description BufferedImage
bitmap()
Returns aBufferedImage
for thisImage
that is ready to be drawn to a graphics context.Region
bitmapBounds()
Returns aRegion
whose width and height indicate that of the bitmap itself; its origin coordinates (Region.lx()
andRegion.by()
) will always be0, 0
.byte[]
data()
Returns the data for this image, encoded according to the format indicated bydataFormat()
; may returnnull
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'sdata()
method.String
id()
Returns the identifier associated with this image's bitmap data, guaranteed to be unique within the scope of its source document.
-
-
-
Method Detail
-
bitmap
BufferedImage bitmap() throws IOException
Returns aBufferedImage
for thisImage
that is ready to be drawn to a graphics context. This method may returnnull
if it is known that the image's data cannot be decoded without producing an exception, or if the image'sdataFormat()
isJPX / JPEG2000
.Note for .NET developers
TheBufferedImage
object returned from this method provides a.getBitmap()
method that efficiently produces a .NETSystem.Drawing.Bitmap
object. So, the pattern you'd typically use withbitmap()
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... }
- Throws:
IOException
-
bitmapBounds
Region bitmapBounds()
Returns aRegion
whose width and height indicate that of the bitmap itself; its origin coordinates (Region.lx()
andRegion.by()
) will always be0, 0
.This does not represent the apparent bounds of the image when positioned on the page; use
Bounded.bounds()
for that.
-
data
byte[] data() throws IOException
Returns the data for this image, encoded according to the format indicated bydataFormat()
; may returnnull
if it is known that the image's data cannot be decoded without producing an exception.- Throws:
IOException
-
dataFormat
Image.Format dataFormat()
Returns the format of the image data available from this image'sdata()
method.
-
id
String id()
Returns the identifier associated with this image's bitmap data, guaranteed to be unique within the scope of its source document.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:- ensures that images that reference the same encoded bitmap data will have the same
id
- retrieves and decodes that bitmap data only when necessary, i.e. when
bitmap()
anddata()
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 apparentBounded.bounds()
on the page, but then never decode the same bitmap data more than once: just track eachImage
'sid
, and reuse thedata()
orbitmap()
objects for any duplicateid
s you find. - ensures that images that reference the same encoded bitmap data will have the same
-
-