Package com.itextpdf.io.image
Class ImageDataFactory
java.lang.Object
com.itextpdf.io.image.ImageDataFactory
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ImageData
create
(byte[] bytes) Create an ImageData instance representing the image from the image bytes.static ImageData
create
(byte[] bytes, boolean recoverImage) Create an ImageData instance representing the image from the image bytes.static ImageData
create
(int width, int height, boolean reverseBits, int typeCCITT, int parameters, byte[] data, int[] transparency) Create an ImageData instance from the passed parameters.static ImageData
create
(int width, int height, int components, int bpc, byte[] data, int[] transparency) Create an ImageData instance from the passed parameters.static ImageData
Gets an instance of an Image from a java.awt.Imagestatic ImageData
Gets an instance of an Image from a java.awt.Image.static ImageData
Create an ImageData instance representing the image from the specified file.static ImageData
Create an ImageData instance representing the image from the specified file.static ImageData
Create an ImageData instance representing the image from the file located at the specified url.static ImageData
Create an ImageData instance representing the image from the file located at the specified url.static ImageData
createBmp
(byte[] bytes, boolean noHeader) Get a bitmap ImageData instance from the provided bytes.static ImageData
Get a bitmap ImageData instance from the specified url.static GifImageData
createGif
(byte[] bytes) Return a GifImage object.static ImageData
createGifFrame
(byte[] bytes, int frame) Returns a specified frame of the gif imagestatic ImageData
createGifFrame
(URL url, int frame) Returns a specified frame of the gif imagecreateGifFrames
(byte[] bytes) ReturnsList
of gif image framescreateGifFrames
(byte[] bytes, int[] frameNumbers) ReturnsList
of gif image framescreateGifFrames
(URL url) ReturnsList
of gif image framescreateGifFrames
(URL url, int[] frameNumbers) ReturnsList
of gif image framesprivate static ImageData
createImageInstance
(byte[] bytes, boolean recoverImage) private static ImageData
createImageInstance
(URL source, boolean recoverImage) static ImageData
createJbig2
(byte[] bytes, int page) static ImageData
createJbig2
(URL url, int page) static ImageData
createJpeg
(byte[] bytes) static ImageData
createJpeg
(URL url) Create anImageData
instance from a Jpeg image urlstatic ImageData
createJpeg2000
(byte[] bytes) static ImageData
createJpeg2000
(URL url) static ImageData
createPng
(byte[] bytes) static ImageData
static ImageData
createRawImage
(byte[] bytes) static ImageData
createTiff
(byte[] bytes, boolean recoverFromImageError, int page, boolean direct) static ImageData
createTiff
(URL url, boolean recoverFromImageError, int page, boolean direct) static boolean
isSupportedType
(byte[] source) Checks if the type of image (based on first 8 bytes) is supported by factory.static boolean
isSupportedType
(ImageType imageType) Checks if the type of image is supported by factory.static boolean
isSupportedType
(URL source) Checks if the type of image (based on first 8 bytes) is supported by factory.processGifImageAndExtractFrames
(int[] frameNumbers, GifImageData image) private static void
validateImageType
(byte[] image, ImageType expectedType) private static void
validateImageType
(URL imageUrl, ImageType expectedType)
-
Constructor Details
-
ImageDataFactory
private ImageDataFactory()
-
-
Method Details
-
create
Create an ImageData instance representing the image from the image bytes.- Parameters:
bytes
- byte representation of the image.recoverImage
- whether to recover from a image error (for TIFF-images)- Returns:
- The created ImageData object.
-
create
Create an ImageData instance representing the image from the image bytes.- Parameters:
bytes
- byte representation of the image.- Returns:
- The created ImageData object.
-
create
Create an ImageData instance representing the image from the file located at the specified url.- Parameters:
url
- location of the imagerecoverImage
- whether to recover from a image error (for TIFF-images)- Returns:
- The created ImageData object.
-
create
Create an ImageData instance representing the image from the file located at the specified url.- Parameters:
url
- location of the image- Returns:
- The created ImageData object.
-
create
Create an ImageData instance representing the image from the specified file.- Parameters:
filename
- filename of the file containing the imagerecoverImage
- whether to recover from a image error (for TIFF-images)- Returns:
- The created ImageData object.
- Throws:
MalformedURLException
- if an error occurred generating the URL.
-
create
Create an ImageData instance representing the image from the specified file.- Parameters:
filename
- filename of the file containing the image- Returns:
- The created ImageData object.
- Throws:
MalformedURLException
- if an error occurred generating the URL.
-
create
public static ImageData create(int width, int height, boolean reverseBits, int typeCCITT, int parameters, byte[] data, int[] transparency) Create an ImageData instance from the passed parameters.- Parameters:
width
- width of the image in pixelsheight
- height of the image in pixelsreverseBits
- whether to reverse the bits stored in data (TIFF images).typeCCITT
- Type of CCITT encodingparameters
- colour space parametersdata
- array containing raw image datatransparency
- array containing transparency information- Returns:
- created ImageData object.
-
create
public static ImageData create(int width, int height, int components, int bpc, byte[] data, int[] transparency) Create an ImageData instance from the passed parameters.- Parameters:
width
- width of the image in pixelsheight
- height of the image in pixelscomponents
- colour space componentsbpc
- bits per colour.data
- array containing raw image datatransparency
- array containing transparency information- Returns:
- created ImageData object.
-
create
Gets an instance of an Image from a java.awt.Image- Parameters:
image
- the java.awt.Image to convertcolor
- if different fromnull
the transparency pixels are replaced by this color- Returns:
- RawImage
- Throws:
IOException
- if an I/O error occurs.
-
create
Gets an instance of an Image from a java.awt.Image.- Parameters:
image
- thejava.awt.Image
to convertcolor
- if different fromnull
the transparency pixels are replaced by this colorforceBW
- iftrue
the image is treated as black and white- Returns:
- RawImage
- Throws:
IOException
- if an I/O error occurs.
-
createBmp
Get a bitmap ImageData instance from the specified url.- Parameters:
url
- location of the image.noHeader
- Whether the image contains a header.- Returns:
- created ImageData
-
createBmp
Get a bitmap ImageData instance from the provided bytes.- Parameters:
bytes
- array containing the raw image datanoHeader
- Whether the image contains a header.- Returns:
- created ImageData
-
createGif
Return a GifImage object. This object cannot be added to a document- Parameters:
bytes
- array containing the raw image data- Returns:
- GifImageData instance.
-
createGifFrame
Returns a specified frame of the gif image- Parameters:
url
- url of gif imageframe
- number of frame to be returned, 1-based- Returns:
- GifImageData instance.
-
createGifFrame
Returns a specified frame of the gif image- Parameters:
bytes
- byte array of gif imageframe
- number of frame to be returned, 1-based- Returns:
- GifImageData instance
-
createGifFrames
ReturnsList
of gif image frames- Parameters:
bytes
- byte array of gif imageframeNumbers
- array of frame numbers of gif image, 1-based- Returns:
- all frames of gif image
-
createGifFrames
ReturnsList
of gif image frames- Parameters:
url
- url of gif imageframeNumbers
- array of frame numbers of gif image, 1-based- Returns:
- all frames of gif image
-
createGifFrames
ReturnsList
of gif image frames- Parameters:
bytes
- byte array of gif image- Returns:
- all frames of gif image
-
createGifFrames
ReturnsList
of gif image frames- Parameters:
url
- url of gif image- Returns:
- all frames of gif image
-
createJbig2
-
createJbig2
-
createJpeg
Create anImageData
instance from a Jpeg image url- Parameters:
url
- URL- Returns:
- the created JPEG image
-
createJpeg
-
createJpeg2000
-
createJpeg2000
-
createPng
-
createPng
-
createTiff
-
createTiff
public static ImageData createTiff(byte[] bytes, boolean recoverFromImageError, int page, boolean direct) -
createRawImage
-
isSupportedType
public static boolean isSupportedType(byte[] source) Checks if the type of image (based on first 8 bytes) is supported by factory.
Note: if this method returnstrue
it doesn't means thatcreate(byte[])
won't throw exception- Parameters:
source
- image raw bytes- Returns:
true
if first eight bytes are recognised by factory as valid image type andfalse
otherwise
-
isSupportedType
Checks if the type of image (based on first 8 bytes) is supported by factory.
Note: if this method returnstrue
it doesn't means thatcreate(byte[])
won't throw exception- Parameters:
source
- image URL- Returns:
true
if first eight bytes are recognised by factory as valid image type andfalse
otherwise
-
isSupportedType
Checks if the type of image is supported by factory.
Note: if this method returnstrue
it doesn't means thatcreate(byte[])
won't throw exception- Parameters:
imageType
- image type- Returns:
true
if image type is supported andfalse
otherwise
-
createImageInstance
-
createImageInstance
-
processGifImageAndExtractFrames
private static List<ImageData> processGifImageAndExtractFrames(int[] frameNumbers, GifImageData image) -
validateImageType
-
validateImageType
-