public class

Bitmap

extends Object
java.lang.Object
   ↳ com.carto.graphics.Bitmap

Class Overview

A class that provides the functionality to store, compress, uncompress and resize basic image formats.
Currently supported formats are png and jpeg. Upon loading compressed images will be converted to
alpha premultiplied uncompressed bitmaps of various image formats.

Summary

Public Constructors
Bitmap(BinaryData pixelData, long width, long height, ColorFormat colorFormat, int bytesPerRow)
Constructs a bitmap from an already decoded vector of bytes.
Public Methods
BinaryData compressToInternal()
Compresses this bitmap to a internal format.
BinaryData compressToPNG()
Compresses this bitmap to a PNG format.
static Bitmap createFromCompressed(BinaryData compressedData)
Creates a new bitmap from compressed byte vector.
synchronized void delete()
boolean equals(Object obj)
Checks if this object is equal to the specified object.
long getBytesPerPixel()
Returns the bytes per pixel parameter of this bitmap.
ColorFormat getColorFormat()
Returns the color format of this bitmap.
long getHeight()
Returns the height of the bitmap.
Bitmap getPaddedBitmap(int xPadding, int yPadding)
Returns paddedsub-bitmap with specified offsets and dimensions.
BinaryData getPixelData()
Returns a copy of the pixel data of this bitmap.
Bitmap getRGBABitmap()
Returns copy of the bitmap converted to RGBA format.
Bitmap getResizedBitmap(long width, long height)
Returns resized version of the bitmap.
Bitmap getSubBitmap(int xOffset, int yOffset, int width, int height)
Returns sub-bitmap with specified offsets and dimensions.
long getWidth()
Returns the width of the bitmap.
int hashCode()
Returns the hash value of this object.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public Bitmap (BinaryData pixelData, long width, long height, ColorFormat colorFormat, int bytesPerRow)

Constructs a bitmap from an already decoded vector of bytes. The bitmap data is expected to be alpha premultiplied, if alpha channel is used.
If the power of two conversion flag is set, additional padding will be added to the image to make it's dimensions power of two.
This can be useful when creating OpenGL textures from the Bitmap, because some GPUs perform badly with non power of two textures.

Parameters
pixelData A vector of decoded, premultiplied bitmap bytes.
width The width of the bitmap.
height The height of the bitmap.
colorFormat The color format of the bitmap.
bytesPerRow The total number of bytes per row. Some bitmaps have additional padding at the end of each row. If the value is negative, then bitmap is assumed to be vertically flipped. In this case absolute value of the bytesPerRow value is used.

Public Methods

public BinaryData compressToInternal ()

Compresses this bitmap to a internal format.
This operation is intended for serialization of the data only, no actual compression is performed.

Returns
  • A byte vector of the serialized data.

public BinaryData compressToPNG ()

Compresses this bitmap to a PNG format.

Returns
  • A byte vector of the PNG's data.

public static Bitmap createFromCompressed (BinaryData compressedData)

Creates a new bitmap from compressed byte vector.
If the power of two conversion flag is set, additional padding will be added to the image to make it's dimensions power of two.

Parameters
compressedData The compressed bitmap data.
Returns
  • The bitmap created from the compressed data. If the decompression fails, null is returned.

public synchronized void delete ()

public boolean equals (Object obj)

Checks if this object is equal to the specified object.

Parameters
obj The reference object.
Returns
  • True when objects are equal, false otherwise.

public long getBytesPerPixel ()

Returns the bytes per pixel parameter of this bitmap. Valid values are 1, 2, 3 and 4.

Returns
  • The bytes per pixel parameter of this bitmap.

public ColorFormat getColorFormat ()

Returns the color format of this bitmap.

Returns
  • The color format of this bitmap.

public long getHeight ()

Returns the height of the bitmap.

Returns
  • The height of the bitmap.

public Bitmap getPaddedBitmap (int xPadding, int yPadding)

Returns paddedsub-bitmap with specified offsets and dimensions.

Parameters
xPadding Padding along X coordinate. If negative value is used, the bitmap is padded from the left. By default, bitmap is padded from the right.
yPadding Padding along Y coordinate. If negative value is used, the bitmap is padded from the top. By default, bitmap is padded from the bottom.
Returns
  • Padded bitmap instance or null in case of error (wrong dimensions).

public BinaryData getPixelData ()

Returns a copy of the pixel data of this bitmap.

Returns
  • A binary data of the bitmap's pixel data.

public Bitmap getRGBABitmap ()

Returns copy of the bitmap converted to RGBA format.

Returns
  • The bitmap with identical dimensions but converted to RGBA format.

public Bitmap getResizedBitmap (long width, long height)

Returns resized version of the bitmap. The power of two padding added during the construction of this bitmap
will be removed prior to resizing. If the power of two conversion flag is set, new padding will be added to the image
after resizing to make it's dimensions power of two.

Parameters
width The new width of this bitmap.
height The new height of this bitmap.
Returns
  • The resized bitmap instance or null in case of error (wrong dimensions).

public Bitmap getSubBitmap (int xOffset, int yOffset, int width, int height)

Returns sub-bitmap with specified offsets and dimensions.

Parameters
xOffset X coordinate offset in the bitmap.
yOffset Y coordinate offset in the bitmap.
width Width of the sub-bitmap.
height Height of the sub-bitmap.
Returns
  • Sub-bitmap instance or null in case of error (wrong dimensions).

public long getWidth ()

Returns the width of the bitmap.

Returns
  • The width of the bitmap.

public int hashCode ()

Returns the hash value of this object.

Returns
  • The hash value of this object.