Foxit PDF SDK
foxit.common.Bitmap Class Reference
Inheritance diagram for foxit.common.Bitmap:
foxit.common.Base

Public Types

enum  DIBFormat {
  DIBFormat.e_DIBInvalid = 0, DIBFormat.e_DIBRgb = 0x018, DIBFormat.e_DIBRgb32 = 0x020, DIBFormat.e_DIBArgb = 0x220,
  DIBFormat.e_DIB8bppMask = 0x108, DIBFormat.e_DIB8bpp = 0x008, DIBFormat.e_DIB8bppGray = 0x1008, DIBFormat.e_DIBAbgr = 0x222,
  DIBFormat.e_DIBRgb565 = 0x565
}
 Enumeration for DIB format. More...
 
enum  InterpolationFlag { InterpolationFlag.e_Downsample = 0x01, InterpolationFlag.e_Quadratic = 0x02, InterpolationFlag.e_Bicubic = 0x04 }
 Enumeration for bitmap interpolation flags. More...
 

Public Member Functions

 Bitmap (int width, int height, Bitmap.DIBFormat format)
 Constructor, with parameters. More...
 
 Bitmap (int width, int height, Bitmap.DIBFormat format, System.IntPtr buffer, int pitch)
 Constructor, with parameters. More...
 
 Bitmap (Bitmap other)
 Constructor, with another bitmap object. More...
 
 Bitmap ()
 Constructor, as an empty bitmap object.
 
RectI CalculateBBoxByColor (uint backgroud_color)
 Calculate the bounding box according to the given background color. More...
 
Bitmap Clone (RectI clip_rect)
 Clone current bitmap, with specified clip rectangle. More...
 
Bitmap ConvertFormat (Bitmap.DIBFormat format, global::System.IntPtr icc_transform)
 Convert a bitmap to another specified DIB format. More...
 
RectI DetectBBoxByColorDiffer (int detection_size, int color_differ)
 Detect the bounding box of content according to the given color difference between content and margin. More...
 
void FillRect (uint color, RectI rect)
 Fill current bitmap with a specified color. More...
 
Bitmap Flip (bool is_flip_horz, bool is_flip_vert)
 Flip bitmap. More...
 
int GetBpp ()
 Get bitmap bits-per-pixel. More...
 
System.IntPtr GetBuffer ()
 Get bitmap buffer. More...
 
Bitmap.DIBFormat GetFormat ()
 Get bitmap format. More...
 
int GetHeight ()
 Get bitmap height. More...
 
Bitmap GetMask (RectI clip_rect)
 Get the mask if bitmap has mask. More...
 
int GetPitch ()
 Get bitmap pitch. More...
 
System.Drawing.Bitmap GetSystemBitmap ()
 Get the bitmap object of the system. More...
 
int GetWidth ()
 Get bitmap width. More...
 
bool IsEmpty ()
 Check whether current object is empty or not. More...
 
Bitmap StretchTo (int dest_width, int dest_height, Bitmap.InterpolationFlag flag, RectI clip_rect)
 Stretch with different size. More...
 
Bitmap SwapXY (bool is_flip_horz, bool is_flip_vert, RectI clip_rect)
 Swap X,Y coordinations of the bitmap. After being swapped, the image can also be flipped at the same time. More...
 
Bitmap TransformTo (Matrix2D matrix, Bitmap.InterpolationFlag flag, ref int out_left, ref int out_top, RectI clip_rect)
 Transform current bitmap (as source bitmap) into destination one. More...
 

Detailed Description

Bitmap is one of most important data structures in Foxit PDF SDK. It is commonly used for rendering. This class can construct a new bitmap object (not retrieved from other object) and offer methods to get information or operate the bitmap.

Member Enumeration Documentation

◆ DIBFormat

Enumeration for DIB format.

Values of this enumeration should be used alone.

Enumerator
e_DIBInvalid 

Invalid DIB format.

e_DIBRgb 

DIB format: 24bpp format, with bits order "Blue, Green, Red". Blue is in the lowest order.

e_DIBRgb32 

DIB format: 32bpp format, with bits order "Blue, Green, Red, not used". Blue is in the lowest order.

e_DIBArgb 

DIB format: 32bpp format, with bits order "Blue, Green, Red, Alpha". Blue is in the lowest order.

e_DIB8bppMask 

DIB format: 8bpp alpha mask.

e_DIB8bpp 

DIB format: 8bpp format, 256 color RGB bitmap.

e_DIB8bppGray 

DIB format: 8bpp format, 256 color GrayScale bitmap.

e_DIBAbgr 

DIB format: 32bpp format, with bits order "Red, Green, Blue, Alpha". Red is in the lowest order.

e_DIBRgb565 

16bpp format, bits order: Red 5 bits, Green 6 bits, Blue 5 bits. Red is the lowest order.

◆ InterpolationFlag

Enumeration for bitmap interpolation flags.

Values of this enumeration can be used alone or in combination.

Enumerator
e_Downsample 

If set, do not do halftone for shrinking or rotating.

e_Quadratic 

If set, do interpolation for stretching or transforming.

e_Bicubic 

If set, do bicubic interpolation for stretching or transforming.

Constructor & Destructor Documentation

◆ Bitmap() [1/3]

foxit.common.Bitmap.Bitmap ( int  width,
int  height,
Bitmap.DIBFormat  format 
)
inline

Constructor, with parameters.

Parameters
[in]widthWidth of bitmap, in pixels. This should be above 0.
[in]heightHeight of bitmap, in pixels. This should be above 0.
[in]formatBitmap format type. Please refer to values starting from foxit.common.Bitmap.DIBFormat.e_DIBRgb and this should be one of these values except foxit.common.Bitmap.DIBFormat.e_DIBInvalid .

◆ Bitmap() [2/3]

foxit.common.Bitmap.Bitmap ( int  width,
int  height,
Bitmap.DIBFormat  format,
System.IntPtr  buffer,
int  pitch 
)
inline

Constructor, with parameters.

If parameter buffer is not null, it should be initialized by application; if parameter buffer is null, Foxit PDF SDK will allocate and initialize the pixels buffer internally.
Application is suggested to use the same colors as Foxit PDF SDK uses internally to initialize bitmap's pixel buffer:

  • For the bitmap without alpha channel, initialize the pixels buffer with 0xFFFFFFFF.

  • For the bitmap with alpha channel, initialize the pixels buffer with 0x00000000.

Parameters
[in]widthWidth of bitmap, in pixels. This should be above 0.
[in]heightHeight of bitmap, in pixels. This should be above 0.
[in]formatBitmap format type. Please refer to values starting from foxit.common.Bitmap.DIBFormat.e_DIBRgb and this should be one of these values except foxit.common.Bitmap.DIBFormat.e_DIBInvalid .
[in]bufferA buffer that specifies bitmap data.
If it is not null, this function will use the parameter buffer to initialize a bitmap. In this case, please do not free the parameter buffer before the life-cycle of parameter bitmap ends.
If it is null, a new bitmap buffer will be created internally.
[in]pitchThe number of bytes for each scan line. This is useful only when parameter buffer is not null. If this value is 0, 4-byte alignment is assumed.

◆ Bitmap() [3/3]

foxit.common.Bitmap.Bitmap ( Bitmap  other)
inline

Constructor, with another bitmap object.

Parameters
[in]otherAnother bitmap object.

Member Function Documentation

◆ CalculateBBoxByColor()

RectI foxit.common.Bitmap.CalculateBBoxByColor ( uint  backgroud_color)
inline

Calculate the bounding box according to the given background color.

This function can support the following formats:
foxit.common.Bitmap.DIBFormat.e_DIB8bppMask , foxit.common.Bitmap.DIBFormat.e_DIB8bpp , foxit.common.Bitmap.DIBFormat.e_DIBRgb , foxit.common.Bitmap.DIBFormat.e_DIBRgb32 , foxit.common.Bitmap.DIBFormat.e_DIBArgb .

Parameters
[in]backgroud_colorA valid background color. Format: 0xAARRGGBB.
Returns
The rectangle of bounding box for content.

◆ Clone()

Bitmap foxit.common.Bitmap.Clone ( RectI  clip_rect)
inline

Clone current bitmap, with specified clip rectangle.

Parameters
[in]clip_rectThe clipping region in current bitmap to specify the region to be cloned.
  • For bitmap format foxit.common.Bitmap.DIBFormat.e_DIBRgb565 , currently only support to clone the whole bitmap, so this should always be null.

  • For rest format, this can be either null or valid. If this is null, that means to clone the whole bitmap. If this is not null, it specifies a clipping region in bitmap to be cloned and the cloned bitmap will have the same size as the clipping region.

Returns
A new bitmap as cloned result.

◆ ConvertFormat()

Bitmap foxit.common.Bitmap.ConvertFormat ( Bitmap.DIBFormat  format,
global::System.IntPtr  icc_transform 
)
inline

Convert a bitmap to another specified DIB format.

Parameters
[in]formatNew bitmap format type. It should be one of following values:
foxit.common.Bitmap.DIBFormat.e_DIB8bppMask , foxit.common.Bitmap.DIBFormat.e_DIB8bpp , foxit.common.Bitmap.DIBFormat.e_DIBRgb , foxit.common.Bitmap.DIBFormat.e_DIBRgb32 , foxit.common.Bitmap.DIBFormat.e_DIBArgb . foxit.common.Bitmap.DIBFormat.e_DIBRgb565 .
[in]icc_transformThe color mapping context for source format to destination format. It can be null, which means not use the color mapping.
Returns
The converted bitmap.

◆ DetectBBoxByColorDiffer()

RectI foxit.common.Bitmap.DetectBBoxByColorDiffer ( int  detection_size,
int  color_differ 
)
inline

Detect the bounding box of content according to the given color difference between content and margin.

This function can support the following formats:
foxit.common.Bitmap.DIBFormat.e_DIB8bppMask , foxit.common.Bitmap.DIBFormat.e_DIB8bpp , foxit.common.Bitmap.DIBFormat.e_DIBRgb , foxit.common.Bitmap.DIBFormat.e_DIBRgb32 , foxit.common.Bitmap.DIBFormat.e_DIBArgb .

Parameters
[in]detection_sizeDetection size to analyze background.
[in]color_differColor difference used to detect margin. The value should be between 0 and 255, and the suggested value is 64.
Returns
The rectangle of bounding box for content.

◆ FillRect()

void foxit.common.Bitmap.FillRect ( uint  color,
RectI  rect 
)
inline

Fill current bitmap with a specified color.

Parameters
[in]colorA color value which is used to fill bitmap. Format: 0xAARRGGBB
[in]rectA rectangle that represents a region in bitmap to specify where the color will be filled. This can be null, which means to fill the whole bitmap.
Returns
None.

◆ Flip()

Bitmap foxit.common.Bitmap.Flip ( bool  is_flip_horz,
bool  is_flip_vert 
)
inline

Flip bitmap.

This function can support following formats:
foxit.common.Bitmap.DIBFormat.e_DIB8bppMask , foxit.common.Bitmap.DIBFormat.e_DIB8bpp , foxit.common.Bitmap.DIBFormat.e_DIBRgb , foxit.common.Bitmap.DIBFormat.e_DIBRgb32 , foxit.common.Bitmap.DIBFormat.e_DIBArgb .

Parameters
[in]is_flip_horzA boolean value to indicate whether to flipping bitmap in horizontal direction: true means a bitmap will be flipped in horizontal direction, and false means not.
[in]is_flip_vertA boolean value to indicate whether to flipping bitmap in vertical direction. true means a bitmap will be flipped in vertical direction, and false means not.
Returns
A new bitmap as flipped result.

◆ GetBpp()

int foxit.common.Bitmap.GetBpp ( )
inline

Get bitmap bits-per-pixel.

Returns
Bitmap bits-per-pixel value.

◆ GetBuffer()

System.IntPtr foxit.common.Bitmap.GetBuffer ( )
inline

Get bitmap buffer.

Bitmap data are organized in scan-lines, from top to down.

Returns
Bitmap buffer.

◆ GetFormat()

Bitmap.DIBFormat foxit.common.Bitmap.GetFormat ( )
inline

Get bitmap format.

Returns
Format value. Please refer to values starting from foxit.common.Bitmap.DIBFormat.e_DIBInvalid and this would be one of these values.

◆ GetHeight()

int foxit.common.Bitmap.GetHeight ( )
inline

Get bitmap height.

Returns
Bitmap height.

◆ GetMask()

Bitmap foxit.common.Bitmap.GetMask ( RectI  clip_rect)
inline

Get the mask if bitmap has mask.

Parameters
[in]clip_rectThe clipping region of current bitmap (as source bitmap). It can be null.
Returns
A new bitmap as mask bitmap. If the return value of function Bitmap.IsEmpty for the returned bitmap object is true, that means current bitmap does not have mask.

◆ GetPitch()

int foxit.common.Bitmap.GetPitch ( )
inline

Get bitmap pitch.

Returns
Bitmap pitch.

◆ GetSystemBitmap()

System.Drawing.Bitmap foxit.common.Bitmap.GetSystemBitmap ( )
inline

Get the bitmap object of the system.

Returns
The bitmap object of the system, if it is null, it mean not supported format or bitmap is empty.

◆ GetWidth()

int foxit.common.Bitmap.GetWidth ( )
inline

Get bitmap width.

Returns
Bitmap width.

◆ IsEmpty()

bool foxit.common.Bitmap.IsEmpty ( )
inline

Check whether current object is empty or not.

When the current object is empty, that means current object is useless.

Returns
true means current object is empty, while false means not.

◆ StretchTo()

Bitmap foxit.common.Bitmap.StretchTo ( int  dest_width,
int  dest_height,
Bitmap.InterpolationFlag  flag,
RectI  clip_rect 
)
inline

Stretch with different size.

If parameter dest_width or parameter dest_height is negative, the bitmap will be flipped. If the stretching is to be done in down-sample mode, that would be much faster than not to be done in down-sample mode, especially when stretching big bitmaps into small ones. Optionally a clipping region in result bitmap coordinate can be specified to limit the size of result bitmap.

Parameters
[in]dest_widthThe width of the destination bitmap.
[in]dest_heightThe height of the destination bitmap.
[in]flagStretch flag, It should be value foxit.common.Bitmap.InterpolationFlag.e_Downsample or foxit.common.Bitmap.InterpolationFlag.e_Quadratic .
[in]clip_rectThe clipping region of destination bitmap. It can be null.
Returns
A new bitmap as stretched result.

◆ SwapXY()

Bitmap foxit.common.Bitmap.SwapXY ( bool  is_flip_horz,
bool  is_flip_vert,
RectI  clip_rect 
)
inline

Swap X,Y coordinations of the bitmap. After being swapped, the image can also be flipped at the same time.

Optionally a clipping region (in destination bitmap coordinate) can be specified to limit the size of result.
Suppose the original image has the following 4 pixels:

         +---+---+
         | 1 | 2 |
         +---+---+
         | 3 | 4 |
         +---+---+
         

Then, depends on parameter is_flip_horz and is_flip_vert, the result would look like: if parameter is_flip_horz = false, parameter is_flip_vert = false:

         +---+---+
         | 1 | 3 |
         +---+---+
         | 2 | 4 |
         +---+---+
         

if parameter is_flip_horz = true, parameter is_flip_vert = false:

         +---+---+
         | 3 | 1 |
         +---+---+
         | 4 | 2 |
         +---+---+
         

if parameter is_flip_horz = false, parameter is_flip_vert = true:

         +---+---+
         | 2 | 4 |
         +---+---+
         | 1 | 3 |
         +---+---+
         

if parameter is_flip_horz = true, parameter is_flip_vert = true:

         +---+---+
         | 4 | 2 |
         +---+---+
         | 3 | 1 |
         +---+---+
         
Parameters
[in]is_flip_horzA boolean value to indicate whether to flipping bitmap in horizontal direction: true means the bitmap will be flipped in horizontal direction, and false means not.
[in]is_flip_vertA boolean value to indicate whether to flipping bitmap in vertical direction: true means the bitmap will be flipped in vertical direction, and false means not.
[in]clip_rectThe clipping region of destination bitmap. This can be null, which means the whole bitmap.
Returns
A new bitmap as swapped result.

◆ TransformTo()

Bitmap foxit.common.Bitmap.TransformTo ( Matrix2D  matrix,
Bitmap.InterpolationFlag  flag,
ref int  out_left,
ref int  out_top,
RectI  clip_rect 
)
inline

Transform current bitmap (as source bitmap) into destination one.

The dimension of returned bitmap always match the dimension of the matrix. If the transformation is to be done in down- sample mode, that would be much faster than not to be done in down-sample mode, especially when transforming big images into small ones. Optionally a clipping region in result bitmap coordinate can be specified to limit the size of result bitmap. The position of left-top corner (in destination coordinate) of the result bitmap would be returned as well.

Parameters
[in]matrixThe transformation matrix.
[in]flagTransform flag. It should be value foxit.common.Bitmap.InterpolationFlag.e_Downsample or foxit.common.Bitmap.InterpolationFlag.e_Quadratic .
[out]out_leftOutput parameter that receives x-coordinate of the left-top corner of the result bitmap in destination coordinate.
[out]out_topOutput parameter that receives y-coordinate of the left-top corner of the result bitmap in destination coordinate.
[in]clip_rectThe clipping region of destination bitmap. It can be null.
Returns
A new bitmap as transformed result.