Class Image
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).
-
Constructor Summary
ConstructorsConstructorDescriptionImage(byte[] buffer, int width, int height, ColorSpace colorSpace) Create an image from byte array.Create a new Image from an existing physical file.Create a new Image from an existing physical file.Image(ImageInputStream stream) Allows to create Image object from ImageInputStream. -
Method Summary
Modifier and TypeMethodDescriptionchangeResolution(int dpi) Create a new image from an existing one modifying the resolution (dots per inch)clone()Makes a copy of the image.clone(EnumSet<ElementCloneFlags> cloneFlags) Makes a copy of the image.colorConvert(Document document, ColorProfile prof, RenderIntent intent, boolean embed) Applies the specified ICC ColorProfile to the Imagevoiddelete()intThe number of bits per component in the image.Return this PDF image as a Java BufferedImage.return the ColorSpace with which this Image was created.byte[]getData()The actual bytes that make up the image, exactly as they appear in the image data.booleanGets whether or not warnings occurred during import of the raster image file.Get the graphic state of the current element.intThe height of the image in pixels.The color rendering intent for the imagebooleanCheck that Image is ImageMask objectGets the decompressed image data from very large images.intThe number of componentsGets, for this image, the soft mask (also an image).The PDFStream object or null if there is no stream associated with the imageintgetWidth()The width of the image in pixels.voidrotate(double angle) Rotate an image on (angle) degree using the matrix [cos(a), sin(a), -sin(a), cos(a), 0, 0].voidSave an image into a particular file format with default parameters for saving.voidsave(String imagefilename, ImageType imageType, ImageSaveParams saveparams) Save an image into a particular file format with the given parameters for saving.voidSet a Compression scheme for the image data.voidsetGraphicState(GraphicState gstate) Set the Graphic State of the current element.voidSetIntent allows to set color rendering intent for the image.voidsetSoftMask(Image softMask) Sets, for this image, the soft mask (also an image).voidtranslate(double tx, double ty) Translate an image by (tx,ty) units using the matrix [ 1 0 0 1 tx ty ].
-
Constructor Details
-
Image
Allows to create Image object from ImageInputStream.- Throws:
IOException
-
Image
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.
- Parameters:
fileName- the filename of the image file.
-
Image
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.
- Parameters:
fileName- the filename of the image file.document- the document in which the image is intended to be used.
-
Image
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.
- Parameters:
buffer- contains Image's datawidth- width of the imageheight- height of the imagecolorSpace- colorspace with wich Image object will be created
-
-
-
Method Details
-
delete
public void delete() -
getBufferedImage
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. -
getData
public byte[] getData()The actual bytes that make up the image, exactly as they appear in the image data. -
getLargeData
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 faciliates retrieving the data in .NET and Java which have 2GB limits on object sizes.
-
getWidth
public int getWidth()The width of the image in pixels. -
getHeight
public int getHeight()The height of the image in pixels. -
getBitsPerComponent
public int getBitsPerComponent()The number of bits per component in the image. -
getNumberComponents
public int getNumberComponents()The number of components -
getIntent
The color rendering intent for the image -
setIntent
SetIntent allows to set color rendering intent for the image.- Parameters:
intent- the intent name
-
getGraphicState
Get the graphic state of the current element. -
setGraphicState
Set the Graphic State of the current element.- Parameters:
gstate- the new/updated Graphic State for the element.
-
changeResolution
Create a new image from an existing one modifying the resolution (dots per inch)- Parameters:
dpi- the new resolution- Returns:
- newimage - the original image modified to the new resolution.
-
translate
public void translate(double tx, double ty) 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.
-
rotate
public void rotate(double angle) 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
Save an image into a particular file format with the given parameters for saving.- Parameters:
imagefilename- The physical image file which will be created.imageType- The ImageType used for saving the image.saveparams- The ImageSaveParams for saving the image.
-
save
Save an image into a particular file format with default parameters for saving.- Parameters:
imagefilename- The physical image file which will be created.imageType- The IMAGETYPE used for saving the image.
-
getStream
The PDFStream object or null if there is no stream associated with the image -
getColorSpace
return the ColorSpace with which this Image was created. -
getCompression
- Returns:
- A compression code which represents the filter used in the image data.
-
setCompression
Set a Compression scheme for the image data.- Parameters:
code- The new new compression scheme to be applied.
-
getSoftMask
Gets, for this image, the soft mask (also an image).- Returns:
- image - an image, the soft mask
-
setSoftMask
Sets, for this image, the soft mask (also an image).- Parameters:
softMask- an image, the soft mask. If set to NULL, the soft mask is removed.
-
getIsImageMask
public boolean getIsImageMask()Check that Image is ImageMask object -
clone
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
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
Applies the specified ICC ColorProfile to the Image- Parameters:
document- The document the element belongs to.prof- The ICC ColorProfile to be applied.intent- The ICC Rendering Intent for the ColorProfileembed- 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:
- A new Image with the applied ICC ColorProfile.
-
getDidWarningsOccurDuringImport
public boolean getDidWarningsOccurDuringImport()Gets whether or not warnings occurred during import of the raster image file.
-