com.foxit.gsdk.image

Class Bitmap

    • Method Summary

      Methods 
      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.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • FORMAT_24BPP_BGR

        public static final int FORMAT_24BPP_BGR
        24bpp format, bits order: Blue, Green, Red. Blue is the lowest order.
        See Also:
        Constant Field Values
      • FORMAT_32BPP_BGRA

        public static final int FORMAT_32BPP_BGRA
        32bpp format, bits order: Blue, Green, Red, Alpha. Blue is the lowest order.
        See Also:
        Constant Field Values
      • FORMAT_8BPP_GRAY

        public static final int FORMAT_8BPP_GRAY
        8bpp format, gray scale.
        See Also:
        Constant Field Values
      • FORMAT_24BPP_RGB

        public static final int FORMAT_24BPP_RGB
        24bpp format, bits order: Red, Green, Blue. Red is the lowest order.
        See Also:
        Constant Field Values
      • FORMAT_32BPP_RGBA

        public static final int FORMAT_32BPP_RGBA
        32bpp format, bits order: Red, Green, Blue, Alpha. Red is the lowest order.
        See Also:
        Constant Field Values
      • FORMAT_8BPP_MASK

        public static final int FORMAT_8BPP_MASK
        8bpp alpha mask.
        See Also:
        Constant Field Values
      • INTERPOLATION_DOWNSAMPLE

        public static final int INTERPOLATION_DOWNSAMPLE
        When set, don't do halftone for shrinking or rotating.
        See Also:
        Constant Field Values
      • INTERPOLATION_QUADRATIC

        public static final int INTERPOLATION_QUADRATIC
        When set, do interpolation for stretching or transforming.
        See Also:
        Constant Field Values
      • INTERPOLATION_BICUBIC

        public static final int INTERPOLATION_BICUBIC
        When set, do bicubic interpolation for stretching or transforming.
        See Also:
        Constant Field Values
    • Method Detail

      • getHandle

        public long getHandle()
      • create

        public static Bitmap create(Size size,
                    int format,
                    java.awt.image.DataBuffer buffer,
                    int stride)
                             throws PDFException
        Create a bitmap.

        Currently, SDK supports to create a bitmap with max size of 16384*16384.

        Parameters:
        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.
        If it's not 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.
        If it's null, a new Bitmap object will be created and initialized internally:
        • If format has alpha channel, it will be initialized with color 0xFFFFFFFF.
        • If 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.
        Returns:
        A Bitmap object.
        Throws:
        PDFException - For more exception information please see definitions PDFException.ERRCODE_XXX.
        See Also:
        PDFException, Rect
      • fillRect

        public void fillRect(long color,
                    Rect rect)
                      throws PDFException
        Fill current bitmap with a specific color.

        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.

        Parameters:
        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.
        Throws:
        PDFException - For more exception information please see definitions PDFException.ERRCODE_XXX.
        See Also:
        PDFException
      • getBuffer

        public java.awt.image.DataBuffer getBuffer()
                                            throws PDFException
        Get the whole data buffer of current bitmap.

        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().

        Returns:
        A DataBuffer object which contains the whole data buffer of current bitmap.
        Throws:
        PDFException - For more exception information please see definitions PDFException.ERRCODE_XXX.
        See Also:
        PDFException
      • getLineBuffer

        public java.awt.image.DataBuffer getLineBuffer(int lineIndex)
                                                throws PDFException
        Get a data buffer of a specific scan-line of current bitmap.

        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().

        Parameters:
        lineIndex - The index of scan-line, from 0 to (height-1) of current bitmap.
        Returns:
        A DataBuffer object which contains the buffer of a specific scan-line.
        Throws:
        PDFException - For more exception information please see definitions PDFException.ERRCODE_XXX.
        See Also:
        PDFException, BufferedImage
      • getLineStride

        public int getLineStride()
                          throws PDFException
        Get a row stride of current bitmap.
        Returns:
        The row stride of current bitmap, which represents the number of bytes for each scan-line.
        Throws:
        PDFException - For more exception information please see definitions PDFException.ERRCODE_XXX.
        See Also:
        PDFException
      • getFlipped

        public Bitmap getFlipped(boolean flipX,
                        boolean flipY)
                          throws PDFException
        Swap X/Y dimensions of current bitmap and generate a flipped bitmap as the result.
        Parameters:
        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.
        Returns:
        A new Bitmap object which represents the flipped result bitmap. Applications should release it by calling function release().
        Throws:
        PDFException - For more exception information please see definitions PDFException.ERRCODE_XXX.
        See Also:
        PDFException
      • stretchTo

        public void stretchTo(Bitmap dstBitmap,
                     int dstLeft,
                     int dstTop,
                     int dstWidth,
                     int dstHeight,
                     Rect dstClipRect,
                     int interpolation)
                       throws PDFException
        Stretch current bitmap into a new bitmap with different size.
        Parameters:
        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.
        Throws:
        PDFException - For more exception information please see definitions PDFException.ERRCODE_XXX.
        See Also:
        PDFException, Rect
      • transformTo

        public void transformTo(Bitmap dstBitmap,
                       Matrix matrix,
                       Rect dstClipRect,
                       int interpolation)
                         throws PDFException
        Transform current bitmap into a new bitmap.
        Parameters:
        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.
        Throws:
        PDFException - For more exception information please see definitions PDFException.ERRCODE_XXX.
        See Also:
        PDFException, Rect, Matrix
      • convertFormat

        public void convertFormat(int format)
                           throws PDFException
        Convert current bitmap to another specific format.
        Parameters:
        format - New bitmap format type. Please refer to constant definitions Bitmap.FORMAT_XXX and this should be one of these constants.
        Throws:
        PDFException - For more exception information please see definitions PDFException.ERRCODE_XXX.
        See Also:
        PDFException
      • convertToBufferedImage

        public java.awt.image.BufferedImage convertToBufferedImage()
                                                            throws PDFException
        Convert current bitmap to a 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).

        Returns:
        A BufferedImage Object.
        Throws:
        PDFException - For more exception information please see definitions PDFException.ERRCODE_XXX.
        See Also:
        PDFException, BufferedImage