# Image Class

> An image resource can either be an image XObject or inline image found in a page's content stream.

- Product: Adobe PDF Library 18
- Language: Java
- Version: APDFL18.0.5PlusP2e
- HTML page: https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Image
- Version index: https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/llms.txt

```java
class Image : Element
```

**Namespace:** `com::datalogics::PDFL`

**Inherits from:** [`Element`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Element.md)

## Description

An image resource can either be an image XObject or inline image found in a page's content stream. An Image Xobject is stored separately from the graphics content stream in a PDF, and so can be used multiple times in the document, even across pages. The image is described in the /Xobject entry in the resources dictionary on the PDF page.

Image size and resoultion: For images that are imported from raster image files, the design width and height are stored in the Image object's Matrix, in the A (width) and D (depth) Matrix members, when the image is imported. These are stored in PDF units.

To derive the effective resolution of an image imported from a raster image file:

Horizontal resolution: divide the Image Width by the Image's Matrix A member and multiply by 72 to scale to DPI (dots per inch).

Vertical resolution: divide the Image Height by the Image's Matrix D member and multiply by 72 to scale to DPI (dots per inch).

**Referenced by:** [`Image`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Image.md), [`ImageCollection`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/ImageCollection.md), [`OCREngine`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/OCREngine.md), [`Page`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Page.md)

**Uses types:** [`Clip`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Clip.md), [`ColorSpace`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/ColorSpace.md), [`Document`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Document.md), [`GraphicState`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/GraphicState.md), [`Image`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Image.md), [`ImageData`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/ImageData.md), [`ImageSaveParams`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/ImageSaveParams.md), [`JavaStreamFile`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/JavaStreamFile.md), [`Matrix`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Matrix.md), [`PDFStream`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/PDFStream.md), [`Rect`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Rect.md)

## Constructors

### Image

```java
com.datalogics.PDFL.Image.Image(StreamFile sf, boolean ignore)
```

*constructor, protected*

**Parameters**

- `sf` (`StreamFile`)
- `ignore` (`boolean`)

### Image

```java
com.datalogics.PDFL.Image.Image(byte[] buffer, int width, int height, ColorSpace colorSpace)
```

*constructor*

**Parameters**

- `buffer` (`byte[]`): contains Image's data
- `width` (`int`): width of the image
- `height` (`int`): height of the image
- `colorSpace` ([`ColorSpace`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/ColorSpace.md)): colorspace with wich Image object will be created

Create an image from byte array. This constructor expects that input buffer is non-padded. If buffer doesn't correspond to the expected format, it will be stripped.
For example: The bitmap data generated by Page's drawContents(DrawParams) function is 32-bit aligned. The PDF image operator expects, however, 8-bit aligned image data. To remedy this difference, we check to see if the 32-bit aligned width is different from the 8-bit aligned width. If so, we fix the image data by stripping off the padding at the end.

### Image

```java
com.datalogics.PDFL.Image.Image(javax.imageio.stream.ImageInputStream stream)
```

*constructor*

**Parameters**

- `stream` (`javax.imageio.stream.ImageInputStream`)

Allows to create Image object from ImageInputStream.

### Image

```java
com.datalogics.PDFL.Image.Image(String fileName)
```

*constructor*

**Parameters**

- `fileName` (`String`): the filename of the image file.

Create a new Image from an existing physical file. This file can be a bitmap, gif, jpeg, png, or a tiff file. An exception will be thrown if the image file is not any of the above.

NOTICE on tiff files: If the tiff file is multi-paged, then the first "page" only of the file will be converted to an Image. See ImageCollection to convert each page in a multi-page tiff file to an Image.

### Image

```java
com.datalogics.PDFL.Image.Image(String fileName, Document document)
```

*constructor*

**Parameters**

- `fileName` (`String`): the filename of the image file.
- `document` ([`Document`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Document.md)): the document in which the image is intended to be used.

Create a new Image from an existing physical file. This file can be a bitmap, gif, jpeg, png, or a tiff file. An exception will be thrown if the image file is not any of the above.

Specifying the document optimizes data usage for this image within that document.

NOTICE on tiff files: If the tiff file is multi-paged, then the first "page" only of the file will be converted to an Image. See ImageCollection to convert each page in a multi-page tiff file to an Image.

## Methods

### changeResolution

```java
Image com.datalogics.PDFL.Image.changeResolution(int dpi)
```

**Parameters**

- `dpi` (`int`): the new resolution

**Returns:** [`Image`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Image.md)

newimage - the original image modified to the new resolution.

Create a new image from an existing one modifying the resolution (dots per inch)

### clone

```java
Image com.datalogics.PDFL.Image.clone()
```

**Returns:** [`Image`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Image.md)

The copied image.

Makes a copy of the image.

Make a copy of an image to obtain a new image that has a distinct set of attributes.

### clone

```java
Image com.datalogics.PDFL.Image.clone(java.util.EnumSet< ElementCloneFlags > cloneFlags)
```

**Parameters**

- `cloneFlags` (`java.util.EnumSet< ElementCloneFlags >`): Flags that modify the cloning operation.

**Returns:** [`Image`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Image.md)

The copied image.

Makes a copy of the image.

Make a copy of an image to obtain a new image that has a distinct set of attributes.

### colorConvert

```java
Image com.datalogics.PDFL.Image.colorConvert(Document document, ColorProfile prof, RenderIntent intent, boolean embed)
```

**Parameters**

- `document` ([`Document`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Document.md)): The document the element belongs to.
- `prof` (`ColorProfile`): The ICC ColorProfile to be applied.
- `intent` (`RenderIntent`): The ICC Rendering Intent for the ColorProfile
- `embed` (`boolean`): If true, embed the color space and make the object calibrated. If it is false and the target profile is CMYK, RGB, or Gray, the colors space of the resulting object, after conversion, will be DeviceCMYK, DeviceRGB, or DeviceGray, respectively.

**Returns:** [`Image`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Image.md)

A new Image with the applied ICC ColorProfile.

Applies the specified ICC ColorProfile to the Image

### delete

```java
synchronized void com.datalogics.PDFL.Image.delete(Boolean disposing)
```

*protected*

**Parameters**

- `disposing` (`Boolean`)

**Returns:** `synchronized void`

### delete

```java
synchronized void com.datalogics.PDFL.Image.delete()
```

**Returns:** `synchronized void`

### finalize

```java
void com.datalogics.PDFL.Image.finalize()
```

*protected*

**Returns:** `void`

### getBitsPerComponent

```java
int com.datalogics.PDFL.Image.getBitsPerComponent()
```

**Returns:** `int`

The number of bits per component (e.g. 1, 2, 4, 8, or 16).

The number of bits per component in the image.

### getBoundingBox

```java
Rect com.datalogics.PDFL.Element.getBoundingBox()
```

**Returns:** [`Rect`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Rect.md)

The bounding box for this element. The coordinates of the bounding box are specified in user space coordinates, relative to the element's Content. Note that user space coordinates correspond to unrotated pages; any rotation specified in the page dictionary is not taken into account.

The bounding box for this element. The bounding box is a rectangle that is guaranteed to encompass the element, but it is not guaranteed to be the smallest box that could contain the element. For example, if the element is a Path that contains an arc, the bounding box encompasses the bezier control points, and not just the curve itself.

### getBufferedImage

```java
java.awt.image.BufferedImage com.datalogics.PDFL.Image.getBufferedImage()
```

**Returns:** `java.awt.image.BufferedImage`

Return this PDF image as a Java BufferedImage.

Images in Gray or RGB color spaces are returned without conversion, while images in other spaces are first converted to RGB.

### getClip

```java
Clip com.datalogics.PDFL.Element.getClip()
```

**Returns:** [`Clip`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Clip.md)

The current Clip for this Element, or NULL if no clip is set.

Gets the current Clip for an Element.

### getColorSpace

```java
ColorSpace com.datalogics.PDFL.Image.getColorSpace()
```

**Returns:** [`ColorSpace`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/ColorSpace.md)

return the ColorSpace with which this Image was created.

### getCompression

```java
CompressionCode com.datalogics.PDFL.Image.getCompression()
```

**Returns:** `CompressionCode`

A compression code which represents the filter used in the image data.

The compression filter applied to the image data.

### getData

```java
byte[] com.datalogics.PDFL.Image.getData()
```

**Returns:** `byte[]`

A byte array containing the raw image data.

The actual bytes that make up the image, exactly as they appear in the image data.

### getDidWarningsOccurDuringImport

```java
boolean com.datalogics.PDFL.Image.getDidWarningsOccurDuringImport()
```

**Returns:** `boolean`

true if warnings were generated during the image import process, false otherwise.

Indicates whether warnings occurred during import of the raster image file.

### getGraphicState

```java
GraphicState com.datalogics.PDFL.Image.getGraphicState()
```

**Returns:** [`GraphicState`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/GraphicState.md)

The GraphicState associated with this image element.

The graphic state of the current element.

### getHeight

```java
int com.datalogics.PDFL.Image.getHeight()
```

**Returns:** `int`

The height of the image in pixels.

The height of the image in pixels.

### getIntent

```java
String com.datalogics.PDFL.Image.getIntent()
```

**Returns:** `String`

The rendering intent name as a string.

The color rendering intent for the image.

### getIsImageMask

```java
boolean com.datalogics.PDFL.Image.getIsImageMask()
```

**Returns:** `boolean`

true if the image is an image mask, false otherwise.

Indicates whether this image is an image mask. An image mask is a 1-bit-per-pixel image used to select painting in the current color rather than displaying image samples.

### getLargeData

```java
java.util.List< ImageData > com.datalogics.PDFL.Image.getLargeData()
```

**Returns:** [`java.util.List< ImageData >`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/ImageData.md)

A list of ImageData chunks containing the decompressed image data.

Gets the decompressed image data from very large images. NOTE: This function is only supported in 64-bit, only if enough contiguous memory is available. The data size must exceed nearly 2GB, otherwise an exception is thrown and you would use the Data member instead to access the image data. The first members of the list returned contain a close to 2GB chunk of the data, but the last member containing the remaining data will be smaller in size. This facilitates retrieving the data in .NET and Java which have 2GB limits on object sizes.

### getMatrix

```java
Matrix com.datalogics.PDFL.Element.getMatrix()
```

**Returns:** [`Matrix`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Matrix.md)

The current transformation matrix applied to this element.

The transformation matrix for the element.

### getNumberComponents

```java
int com.datalogics.PDFL.Image.getNumberComponents()
```

**Returns:** `int`

The number of color components (e.g. 1 for grayscale, 3 for RGB, 4 for CMYK).

The number of color components in the image.

### getSoftMask

```java
Image com.datalogics.PDFL.Image.getSoftMask()
```

**Returns:** [`Image`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Image.md)

image - an image, the soft mask

Gets, for this image, the soft mask (also an image).

### getStream

```java
PDFStream com.datalogics.PDFL.Image.getStream()
```

**Returns:** [`PDFStream`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/PDFStream.md)

The PDFStream object, or null if there is no stream associated with the image.

The PDFStream object associated with the image.

### getWidth

```java
int com.datalogics.PDFL.Image.getWidth()
```

**Returns:** `int`

The width of the image in pixels.

The width of the image in pixels.

### rotate

```java
void com.datalogics.PDFL.Image.rotate(double angle)
```

**Parameters**

- `angle` (`double`): The rotation angle in degrees, counterclockwise.

**Returns:** `void`

Rotate an image on (angle) degree using the matrix [cos(a), sin(a), -sin(a), cos(a), 0, 0]. For images, this rotate is done without regard to the primary scaling of the original image.

### save

```java
void com.datalogics.PDFL.Image.save(String imagefilename, ImageType imageType)
```

**Parameters**

- `imagefilename` (`String`): The physical image file which will be created.
- `imageType` (`ImageType`): The IMAGETYPE used for saving the image.

**Returns:** `void`

Save an image into a particular file format with default parameters for saving.

### save

```java
void com.datalogics.PDFL.Image.save(String imagefilename, ImageType imageType, ImageSaveParams saveparams)
```

**Parameters**

- `imagefilename` (`String`): The physical image file which will be created.
- `imageType` (`ImageType`): The ImageType used for saving the image.
- `saveparams` ([`ImageSaveParams`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/ImageSaveParams.md)): The ImageSaveParams for saving the image.

**Returns:** `void`

Save an image into a particular file format with the given parameters for saving.

### scale

```java
void com.datalogics.PDFL.Element.scale(double sx, double sy)
```

**Parameters**

- `sx` (`double`): The horizontal scale factor.
- `sy` (`double`): The vertical scale factor.

**Returns:** `void`

Scale an element by (sx,sy) units using the matrix [ sx 0 0 sy 0 0 ].

### setClip

```java
void com.datalogics.PDFL.Element.setClip(Clip clip)
```

**Parameters**

- `clip` ([`Clip`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Clip.md)): The clip to set as the current clip for this element, or NULL to remove clipping.

**Returns:** `void`

Sets the current Clip for an Element.

### setCompression

```java
void com.datalogics.PDFL.Image.setCompression(CompressionCode code)
```

**Parameters**

- `code` (`CompressionCode`): The new new compression scheme to be applied.

**Returns:** `void`

Set a Compression scheme for the image data.

### setGraphicState

```java
void com.datalogics.PDFL.Image.setGraphicState(GraphicState gstate)
```

**Parameters**

- `gstate` ([`GraphicState`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/GraphicState.md)): the new/updated Graphic State for the element.

**Returns:** `void`

Set the Graphic State of the current element.

### setIntent

```java
void com.datalogics.PDFL.Image.setIntent(String intent)
```

**Parameters**

- `intent` (`String`): the intent name

**Returns:** `void`

SetIntent allows to set color rendering intent for the image.

### setMatrix

```java
void com.datalogics.PDFL.Element.setMatrix(Matrix matrix)
```

**Parameters**

- `matrix` ([`Matrix`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Matrix.md)): The transformation matrix for the element.

**Returns:** `void`

Set the transformation matrix for the element.

### setSoftMask

```java
void com.datalogics.PDFL.Image.setSoftMask(Image softMask)
```

**Parameters**

- `softMask` ([`Image`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Image.md)): an image, the soft mask. If set to NULL, the soft mask is removed.

**Returns:** `void`

Sets, for this image, the soft mask (also an image).

### translate

```java
void com.datalogics.PDFL.Image.translate(double tx, double ty)
```

**Parameters**

- `tx` (`double`): The horizontal translation distance in user space units.
- `ty` (`double`): The vertical translation distance in user space units.

**Returns:** `void`

Translate an image by (tx,ty) units using the matrix [ 1 0 0 1 tx ty ]. For images, this translation is done without regard to the scaling and rotation of the original image.

To ensure that this translation can be done, do the translation before any further rotation or scaling.
