public class Bitmap
extends java.lang.Object
Bitmap
represents a bitmap object, which contains the bitmap data.
It can be constructed by the following way.
Example:
Size size = new Size(100, 100); Bitmap bitmap = Bitmap.create(size, FORMAT_24BPP_BGR, null, 0);
Modifier and Type | Field and Description |
---|---|
static int |
FORMAT_24BPP_BGR
24bpp format, bits order: Blue, Green, Red.
|
static int |
FORMAT_24BPP_RGB
24bpp format, bits order: Red, Green, Blue.
|
static int |
FORMAT_32BPP_BGRA
32bpp format, bits order: Blue, Green, Red, Alpha.
|
static int |
FORMAT_32BPP_RGBA
32bpp format, bits order: Red, Green, Blue, Alpha.
|
static int |
FORMAT_8BPP_GRAY
8bpp format, gray scale.
|
static int |
FORMAT_8BPP_MASK
8bpp alpha mask.
|
static int |
INTERPOLATION_BICUBIC
When set, do bicubic interpolation for stretching or transforming.
|
static int |
INTERPOLATION_DOWNSAMPLE
When set, don't do halftone for shrinking or rotating.
|
static int |
INTERPOLATION_QUADRATIC
When set, do interpolation for stretching or transforming.
|
Modifier and Type | Method and Description |
---|---|
Bitmap |
cloneBitmap()
Clone current bitmap and generate a cloned bitmap.
|
void |
convertFormat(int format)
Convert current bitmap to another specific format.
|
java.awt.image.BufferedImage |
convertToBufferedImage()
Convert current bitmap to a
BufferedImage object. |
static Bitmap |
create(Size size,
int format,
java.awt.image.DataBuffer buffer,
int stride)
Create a bitmap.
|
void |
fillRect(long color,
Rect rect)
Fill current bitmap with a specific color.
|
java.awt.image.DataBuffer |
getBuffer()
Get the whole data buffer of current bitmap.
|
Bitmap |
getFlipped(boolean flipX,
boolean flipY)
Swap X/Y dimensions of current bitmap and generate a flipped bitmap as the result.
|
int |
getFormat()
Get format of current bitmap.
|
long |
getHandle() |
java.awt.image.DataBuffer |
getLineBuffer(int lineIndex)
Get a data buffer of a specific scan-line of current bitmap.
|
int |
getLineStride()
Get a row stride of current bitmap.
|
Size |
getSize()
Get the size of current bitmap.
|
void |
release()
Release current bitmap.
|
void |
stretchTo(Bitmap dstBitmap,
int dstLeft,
int dstTop,
int dstWidth,
int dstHeight,
Rect dstClipRect,
int interpolation)
Stretch current bitmap into a new bitmap with different size.
|
void |
transformTo(Bitmap dstBitmap,
Matrix matrix,
Rect dstClipRect,
int interpolation)
Transform current bitmap into a new bitmap.
|
public static final int FORMAT_24BPP_BGR
public static final int FORMAT_32BPP_BGRA
public static final int FORMAT_8BPP_GRAY
public static final int FORMAT_24BPP_RGB
public static final int FORMAT_32BPP_RGBA
public static final int FORMAT_8BPP_MASK
public static final int INTERPOLATION_DOWNSAMPLE
public static final int INTERPOLATION_QUADRATIC
public static final int INTERPOLATION_BICUBIC
public long getHandle()
public static Bitmap create(Size size, int format, java.awt.image.DataBuffer buffer, int stride) throws PDFException
Currently, SDK supports to create a bitmap with max size of 16384*16384.
size
- The size of the bitmap, in pixels.format
- Bitmap format type. Please refer to constant definitions FORMAT_XXX
and this should be one of these constants.buffer
- A DataBuffer
object that specifies a bitmap data.null
, it should point to a valid DIB buffer which represents the data of a standard DIB format.
And this function will use the parameter buffer
to create and initialize a Bitmap
object.
In this case, please do not free buffer
before the created Bitmap
object is released.null
, a new Bitmap
object will be created and initialized internally:
format
has alpha channel, it will be initialized with color 0xFFFFFFFF.format
doesn't have alpha channel, it will be initialized with color 0x00000000.stride
- The number of bytes for each scan line, only useful when parameter buffer
is not null
.
If not specified, 4-byte alignment is assumed.
If parameter buffer
is null
, just set this as 0.Bitmap
object.PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
,
Rect
public void release() throws PDFException
If an external buffer is used (specified by parameter buffer
in calling function create(Size, int, DataBuffer, int)
),
the external buffer should not be released by application until current bitmap is released.
PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
public void fillRect(long color, Rect rect) throws PDFException
If the format of bitmap is FORMAT_8BPP_GRAY
, the gray value for parameter color
is computed according to the NTSC video standard, which determines how a color television signal
is rendered on a black-and-white television set:
gray = 0.3*red + 0.59*green + 0.11*blue
For more details, please refer to session 6.2.1 "Conversion between DeviceGray and DeviceRGB" in PDF Reference1.7 page 481.
color
- Color used to fill. Format: 0xAARRGGBB.
Please ensure to input the color value with the correct format.rect
- A Rect
object to specify the filling rectangle.
If it's null
, the whole bitmap will be filled with the specific color.PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
public int getFormat() throws PDFException
Bitmap.FORMAT_XXX
and this will be one of these constants.PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
public Size getSize() throws PDFException
Size
object that receives the size(width and height) of
current bitmap in pixels.PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
,
Size
public java.awt.image.DataBuffer getBuffer() throws PDFException
This function is to get all the bitmap data of current bitmap.
If application wants to get the data of a specific scan line, please refer to getLineBuffer(int)
.
If application wants to get a BufferedImage
object directly, please refer to convertToBufferedImage()
.
DataBuffer
object which contains the whole data buffer of current bitmap.PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
public java.awt.image.DataBuffer getLineBuffer(int lineIndex) throws PDFException
Bitmap data are organized in scan-lines, from top to down.
Application can call this function to get the bitmap data of a specific scan line.
If application wants to get the whole data of current bitmap, please refer to getBuffer()
.
If application wants to get a BufferedImage
object directly, please refer to convertToBufferedImage()
.
lineIndex
- The index of scan-line, from 0 to (height-1) of current bitmap.DataBuffer
object which contains the buffer of a specific scan-line.PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
,
BufferedImage
public int getLineStride() throws PDFException
PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
public Bitmap getFlipped(boolean flipX, boolean flipY) throws PDFException
flipX
- A boolean value to indicate whether to flip the bitmap in horizontal direction (left/right).
If it's true
, the bitmap will be flipped in horizontal direction.flipY
- A boolean value to indicate whether to flip the bitmap in vertical direction (up/down).
If it's true
, the bitmap will be flipped in vertical direction.Bitmap
object which represents the flipped result bitmap.
Applications should release it by calling function release()
.PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
public void stretchTo(Bitmap dstBitmap, int dstLeft, int dstTop, int dstWidth, int dstHeight, Rect dstClipRect, int interpolation) throws PDFException
dstBitmap
- A Bitmap
object which is the destination bitmap.dstLeft
- Left position in the destination bitmap,
from which current bitmap will be stretched.dstTop
- Top position in the destination bitmap,
from which current bitmap will be stretched.dstWidth
- Width in the destination bitmap. It should be greater than 0.dstHeight
- Height in the destination bitmap. It should be greater than 0.dstClipRect
- A Rect
object which is the clipping rectangle in the destination bitmap.
If it's null
, it means no clip is used.interpolation
- An integer value, representing which interpolation algorithm will be used to stretch a bitmap.
Please refer to constants definitions Bitmap.INTERPOLATION_XXX
and this should be one of these constants.PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
,
Rect
public void transformTo(Bitmap dstBitmap, Matrix matrix, Rect dstClipRect, int interpolation) throws PDFException
dstBitmap
- A Bitmap
object which is the destination bitmap.matrix
- A Matrix
object which specifies a transformation matrix.dstClipRect
- A Rect
object which is the clipping rectangle in destination bitmap.
If it's null
, it means no clip is used.interpolation
- An integer value, representing which interpolation algorithm will be used to stretch a bitmap.
Please refer to constants definitions Bitmap.INTERPOLATION_XXX
and this should be one of these constants.PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
,
Rect
,
Matrix
public void convertFormat(int format) throws PDFException
format
- New bitmap format type. Please refer to constant definitions Bitmap.FORMAT_XXX
and this should be one of these constants.PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
public Bitmap cloneBitmap() throws PDFException
Bitmap
object which represents the cloned bitmap.release()
.PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
public java.awt.image.BufferedImage convertToBufferedImage() throws PDFException
BufferedImage
object.
This function offers a convenient method to convert current bitmap directly to a BufferedImage
object.
If application wants to get the whole data of current bitmap, please refer to getBuffer()
.
If application wants to get the data of a specific scan-line, please refer to getLineBuffer(int)
.
BufferedImage
Object.PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
,
BufferedImage