[]
        
(Showing Draft Content)

Bitmap

Class: Bitmap

Represents an uncompressed in-memory bitmap.

Extends

Constructors

Constructor

new Bitmap(
   width, 
   height, 
   backColor?): Bitmap;

Creates a Bitmap instance with optionally initialized pixels.

Parameters

width

number

The bitmap width, in pixels.

height

number

The bitmap height, in pixels.

backColor?

Color

The optional background color to fill the Bitmap.

Returns

Bitmap

Overrides

ObjectBase.constructor

Constructor

new Bitmap(
   om, 
   width, 
   height, 
   backColor?): Bitmap;

Creates a Bitmap instance with optionally initialized pixels.

Parameters

om

ObjectManager

An object manager that controls the lifetime of the Bitmap object.

width

number

The bitmap width, in pixels.

height

number

The bitmap height, in pixels.

backColor?

Color

The optional background color to fill the Bitmap.

Returns

Bitmap

Overrides

ObjectBase.constructor

Accessors

blackAndWhite

Get Signature

get blackAndWhite(): boolean;

Returns true if all pixels in the image are either black or white.

Returns

boolean


context

Get Signature

get context(): BmpContext;

Gets the current BmpContext for this Bitmap.

Returns

BmpContext


grayscale

Get Signature

get grayscale(): boolean;

Determines whether the image contains only opaque grayscale pixels.

Returns

boolean


height

Get Signature

get height(): number;

Gets the height of the bitmap, in pixels.

Returns

number


id

Get Signature

get id(): number;

Gets the reference to the object.

Returns

number

Inherited from

ObjectBase.id


om

Get Signature

get om(): ObjectManager;

Gets the owner ObjectManager instance.

Returns

ObjectManager

Inherited from

ObjectBase.om


width

Get Signature

get width(): number;

Gets the width of the bitmap, in pixels.

Returns

number

Methods

addGlow()

addGlow(
   glowColor, 
   glowOpacity?, 
   inflationRadius?, 
   gaussianBlurRadius?): Bitmap;

Creates a bitmap with glow effect from the current image. The glow effect inflates all non-transparent areas of an image by a specified amount, then applies a Gaussian blur to make the border smooth. The effect appears only if some pixels of the current image are transparent or semi-transparent.

Parameters

glowColor

Color

The glow color.

glowOpacity?

number

The glow opacity, between 0 and 1.

inflationRadius?

number

The glow inflation radius, in pixels.

gaussianBlurRadius?

number

The Gaussian blur radius, in pixels.

Returns

Bitmap

A new Bitmap with glow effect.


addShadow()

addShadow(
   xOffset, 
   yOffset, 
   shadowColor, 
   shadowOpacity?, 
   gaussianBlurRadius?): Bitmap;

Creates a bitmap with shadow from the current image. The shadow appears only if some pixels of the current image are transparent or semi-transparent.

Parameters

xOffset

number

The horizontal offset of the shadow, in pixels.

yOffset

number

The vertical offset of the shadow, in pixels.

shadowColor

Color

The shadow color.

shadowOpacity?

number

The shadow opacity, between 0 and 1.

gaussianBlurRadius?

number

The shadow blur radius, in pixels.

Returns

Bitmap

A new Bitmap with shadow.


adjustLevels()

adjustLevels(
   blackPoint, 
   whitePoint, 
   outputBlack, 
   outputWhite, 
   midtone?): void;

Adjusts the levels of an image histogram. The method maps the input range of values (blackPoint..whitePoint) to the output range (outputBlack..outputWhite) using the specified gamma correction (midtone).

Parameters

blackPoint

Color

The input black point color.

whitePoint

Color

The input white point color.

outputBlack

Color

The output black point color.

outputWhite

Color

The output white point color.

midtone?

number

The value of gamma correction.

Returns

void


alphaBlend()

alphaBlend(
   srcBitmap, 
   dstX, 
   dstY, 
   options?): void;

Draws the source bitmap with the specified opacity into the current Bitmap.

Parameters

srcBitmap

Bitmap

The Bitmap with the source color data to draw.

dstX

number

The x-coordinate of the destination rectangle, in pixels.

dstY

number

The y-coordinate of the destination rectangle, in pixels.

options?

AlphaBlendOptions

The alpha blend options.

Returns

void


applyBilevelTransparencyMask()

applyBilevelTransparencyMask(mask, bounds?): void;

Applies a bi-level transparency mask to the current image or its portion.

Parameters

mask

BilevelBitmap

A BilevelBitmap with the transparency mask.

bounds?

Bounds

The target rectangle of the bitmap.

Returns

void


applyBradleyThresholdingEffect()

applyBradleyThresholdingEffect(
   sDivider?, 
   t?, 
   bounds?): void;

Applies the in-place effect that converts a monochromatic (grayscale) image to bi-level image using Bradley and Roth's method of adaptive image thresholding.

Parameters

sDivider?

number

A divider of the image width to calculate the value of s.

t?

number

The value of t parameter.

bounds?

Bounds

The target rectangle of the Bitmap, or the entire Bitmap if null.

Returns

void


applyBrightnessContrast()

applyBrightnessContrast(
   brightness, 
   contrast, 
   bounds?): void;

Applies the in-place effect that updates the image brightness and contrast.

Parameters

brightness

number

A value from -255 to 255 for adjusting the brightness level.

contrast

number

A value from -255 to 255 for adjusting the contrast level.

bounds?

Bounds

The target rectangle of the Bitmap, or the entire Bitmap if null.

Returns

void


applyDitheringEffect()

applyDitheringEffect(ditheringMethod?, bounds?): void;

Applies the in-place effect that converts a monochromatic (grayscale) image to bi-level image with two-dimensional error diffusion dithering.

Parameters

ditheringMethod?

DitheringMethod

The method of two-dimensional error diffusion dithering. The default is Floyd-Steinberg method.

bounds?

Bounds

The target rectangle of the Bitmap, or the entire Bitmap if null.

Returns

void


applyGammaCorrection()

applyGammaCorrection(gamma?, bounds?): void;

Applies the in-place effect that applies gamma correction to the image.

Parameters

gamma?

number

A value of Gamma, from 0.001 to 1000.

bounds?

Bounds

The target rectangle of the Bitmap, or the entire Bitmap if null.

Returns

void


applyGaussianBlur()

applyGaussianBlur(
   radius?, 
   borderMode?, 
   borderColor?, 
   bounds?): void;

Applies the in-place effect that applies a Gaussian blur to the image.

Parameters

radius?

number

The radius of the blur, in pixels.

borderMode?

GaussianBlurBorderMode

The mapping mode for the pixels outside of the border, "RepeatEdge" if null.

borderColor?

Color

The color used to blend with the edge pixels of the image, "Transparent" if null.

bounds?

Bounds

The target rectangle of the Bitmap, or the entire Bitmap if null.

Returns

void


applyGrayscaleEffect()

applyGrayscaleEffect(standard?, bounds?): void;

Applies the in-place effect that converts an image to monochromatic gray.

Parameters

standard?

GrayscaleStandard

A grayscale standard used for converting full-color image to monochromatic gray.

bounds?

Bounds

The target rectangle of the Bitmap, or the entire Bitmap if null.

Returns

void


applyGrayscaleTransparencyMask()

applyGrayscaleTransparencyMask(mask, bounds?): void;

Applies a grayscale transparency mask to the current image or its portion.

Parameters

mask

GrayscaleBitmap

A GrayscaleBitmap with the transparency mask.

bounds?

Bounds

The target rectangle of the bitmap.

Returns

void


applyHueRotation()

applyHueRotation(angleInDegrees, bounds?): void;

Applies the in-place effect that alters the hue of an image based on the rotation angle.

Parameters

angleInDegrees

number

The angle to rotate the hue, in degrees.

bounds?

Bounds

The target rectangle of the Bitmap, or the entire Bitmap if null.

Returns

void


applyLuminanceToAlpha()

applyLuminanceToAlpha(bounds?): void;

Applies the in-place effect that sets the alpha channel to the luminance of the image and sets the color channels to 0.

Parameters

bounds?

Bounds

The target rectangle of the Bitmap, or the entire Bitmap if null.

Returns

void


applyOpacityEffect()

applyOpacityEffect(opacity, bounds?): void;

Applies the in-place effect that adjusts the opacity of an image by multiplying the alpha channel of the input by the specified opacity value.

Parameters

opacity

number

The multiplier to the input image's alpha channel. The minimum value is 0.0 and the maximum value is 1.0.

bounds?

Bounds

The target rectangle of the Bitmap, or the entire Bitmap if null.

Returns

void


applyOtsuThresholdingEffect()

applyOtsuThresholdingEffect(bounds?): void;

Applies the in-place effect that converts a monochromatic (grayscale) image to bi-level image using Otsu's method of clustering-based image thresholding.

Parameters

bounds?

Bounds

The target rectangle of the Bitmap, or the entire Bitmap if null.

Returns

void


applySaturationEffect()

applySaturationEffect(saturation, bounds?): void;

Applies the in-place effect that alters the saturation of an image.

Parameters

saturation

number

The saturation of the image between 0.0 (monochrome) and 1.0 (fully saturated).

bounds?

Bounds

The target rectangle of the Bitmap, or the entire Bitmap if null.

Returns

void


applySepiaEffect()

applySepiaEffect(bounds?): void;

Applies the in-place effect that converts an image to sepia tones.

Parameters

bounds?

Bounds

The target rectangle of the Bitmap, or the entire Bitmap if null.

Returns

void


applySoftEdges()

applySoftEdges(inflationRadius?, gaussianBlurRadius?): void;

Applies a soft edges effect to the current image. The soft edges effect deflates all non-transparent areas of an image by a specified amount, then applies a Gaussian blur to make the border smooth.

Parameters

inflationRadius?

number

The negative radius of inflation, in pixels.

gaussianBlurRadius?

number

The Gaussian blur radius, in pixels.

Returns

void


applyTemperatureAndTint()

applyTemperatureAndTint(
   temperature, 
   tint, 
   bounds?): void;

Applies the in-place effect that alters the temperature and tint of an image.

Parameters

temperature

number

Specifies how much to increase or decrease the temperature of the input image. The allowed range is between -1.0 and 1.0.

tint

number

Specifies how much to increase or decrease the tint of the input image. The allowed range is between -1.0 and 1.0.

bounds?

Bounds

The target rectangle of the Bitmap, or the entire Bitmap if null.

Returns

void


autoLevels()

autoLevels(
   keepRelativeIntensities?, 
   lowClipFraction?, 
   highClipFraction?): void;

Modifies R, G, B color intensities such that the maximum range of values (0..255) is fully covered.

Parameters

keepRelativeIntensities?

boolean

Indicates if the method should keep the relative intensities of the color channels unchanged.

lowClipFraction?

number

The fraction of extremely low values to be clipped, not greater than 0.1.

highClipFraction?

number

The fraction of extremely high values to be clipped, not greater than 0.1.

Returns

void


bitBlt()

bitBlt(
   srcBitmap, 
   dstX, 
   dstY, 
   options?): void;

Performs a bit-block transfer of the color data corresponding to a rectangle of pixels from the specified source bitmap into the current Bitmap.

Parameters

srcBitmap

Bitmap

The Bitmap with the source color data to transfer.

dstX

number

The x-coordinate of the destination rectangle, in pixels.

dstY

number

The y-coordinate of the destination rectangle, in pixels.

options?

BitBltOptions

The source coordinates, size, and other options.

Returns

void


clear()

clear(color, bounds?): void;

Clears the whole Bitmap or its part with specified color.

Parameters

color

Color

The color to fill the image.

bounds?

Bounds

The target rectangle of the Bitmap.

Returns

void


clip()

Call Signature

clip(
   x, 
   y, 
   width, 
   height, 
   metadataOnly?): Bitmap;

Creates a new Bitmap with a fragment of the image.

Parameters
x

number

The X coordinate of the clipping rectangle.

y

number

The Y coordinate of the clipping rectangle.

width

number

The width of the clipping rectangle.

height

number

The height of the clipping rectangle.

metadataOnly?

boolean

Specifies whether to copy the image metadata only, not actual pixel data. The default is false.

Returns

Bitmap

A new Bitmap with a fragment of the source image.

Call Signature

clip(bounds, metadataOnly?): Bitmap;

Creates a new Bitmap with a fragment of the image.

Parameters
bounds

Bounds

Clipping rectangle of the source image to be extracted as a new Bitmap.

metadataOnly?

boolean

Specifies whether to copy the image metadata only, not actual pixel data. The default is false.

Returns

Bitmap

A new Bitmap with a fragment of the source image.


clone()

clone(metadataOnly?): Bitmap;

Creates a new Bitmap with a copy of the image.

Parameters

metadataOnly?

boolean

specifies whether to copy the image metadata only, not actual pixel data.

Returns

Bitmap

A new Bitmap with a copy of the source image.


compositeAndBlend()

compositeAndBlend(
   srcBitmap, 
   dstX, 
   dstY, 
   options?): void;

Applies the algorithms of Porter Duff compositing and blending to the current Bitmap (used as backdrop, destination) and the source Bitmap.

Parameters

srcBitmap

Bitmap

The Bitmap with the source color data to composite.

dstX

number

The x-coordinate of the destination rectangle, in pixels.

dstY

number

The y-coordinate of the destination rectangle, in pixels.

options?

CompositeAndBlendOptions

The compositing and blending options.

Returns

void


convertToOpaque()

convertToOpaque(backColor, bounds?): void;

Converts an image with transparent or semitransparent pixels to fully opaque with specified background color.

Parameters

backColor

Color

The color to be used as background for transparent pixels.

bounds?

Bounds

The target rectangle of the bitmap.

Returns

void


exportColorChannel()

exportColorChannel(destination, colorChannel): void;

Copies data from one color channel of the current Bitmap to an existing GrayscaleBitmap of the same pixel size.

Parameters

destination

GrayscaleBitmap

The target GrayscaleBitmap.

colorChannel

ColorChannel

A channel of the source Bitmap to be exported.

Returns

void


flipRotate()

flipRotate(action, clipBounds?): Bitmap;

Produces a flipped (horizontal or vertical) and/or rotated (by 90 degree increments) bitmap. The source Bitmap remains unchanged.

Parameters

action

FlipRotateAction

The operation to be applied.

clipBounds?

Bounds

Clipping rectangle specifying the area of the source image to be processed.

Returns

Bitmap

A new Bitmap with transformed image.


free()

free(): void;

Detaches the object from the ObjectManager and deallocates its memory, if possible.

Returns

void

Inherited from

ObjectBase.free


getContentRect()

getContentRect(backColor): Rect;

Returns the coordinates of a rectangle with colors different from backColor.

Parameters

backColor

Color

The background color.

Returns

Rect

A part of the image rectangle excluding the margins with background color.


hasTransparentPixels()

hasTransparentPixels(bounds?): boolean;

Determines whether the image contains transparent or semitransparent pixels.

Parameters

bounds?

Bounds

The source rectangle to analyse.

Returns

boolean

true if at least one non-opaque pixel was found, false otherwise.


importColorChannel()

importColorChannel(source, colorChannel): void;

Copies data from a GrayscaleBitmap to one color channel of the current Bitmap of the same pixel size.

Parameters

source

GrayscaleBitmap

A GrayscaleBitmap with source data.

colorChannel

ColorChannel

A channel of the destination Bitmap to be updated.

Returns

void


newContext()

newContext(bmpContextProperties?): BmpContext;

Creates a BmpContext for the current Bitmap and optionally fills it with a background color.

Parameters

bmpContextProperties?

BmpContextProperties

The settings for creating a DrawingContext for Bitmap.

Returns

BmpContext

An instance of BmpContext.


rebind()

rebind(omTo): void;

Rebinds the object from the current ObjectManager to the specified one.

Parameters

omTo

ObjectManager

The new ObjectManager for the object.

Returns

void

Inherited from

ObjectBase.rebind


resize()

Call Signature

resize(
   width, 
   height, 
   interpolationMode?): Bitmap;

Creates a new Bitmap with a resized image fragment. The source Bitmap remains unchanged.

Parameters
width

number

The width of the resized image, in pixels.

height

number

The height of the resized image, in pixels.

interpolationMode?

InterpolationMode

The interpolation mode to use when scaling. The default is Linear.

Returns

Bitmap

A new Bitmap with resized image.

Call Signature

resize(options): Bitmap;

Creates a new Bitmap with a resized image fragment. The source Bitmap remains unchanged.

Parameters
options

ResizeBitmapOptions

The resizing options.

Returns

Bitmap

A new Bitmap with resized image.


saveAsJpeg()

saveAsJpeg(quality?): Uint8Array;

Saves the Bitmap as an array with JPEG-encoded image data.

Parameters

quality?

number

The image quality from 0 (best compression) to 100 (best quality).

Returns

Uint8Array

A byte array with JPEG-encoded image data.


saveAsJpegImage()

saveAsJpegImage(quality?): Image;

Saves the Bitmap as a JPEG-encoded Image.

Parameters

quality?

number

The image quality from 0 (best compression) to 100 (best quality).

Returns

Image

The resulting Image object.


saveAsPng()

saveAsPng(fastest?): Uint8Array;

Saves the Bitmap as an array with PNG-encoded image data.

Parameters

fastest?

boolean

if true, forces the operation to work as fast as possible at the expence of lower compression ratio.

Returns

Uint8Array

A byte array with PNG-encoded image data.


saveAsPngImage()

saveAsPngImage(fastest?): Image;

Saves the Bitmap as a PNG-encoded Image.

Parameters

fastest?

boolean

if true, forces the operation to work as fast as possible at the expence of lower compression ratio.

Returns

Image

The resulting Image object.


toBilevelBitmap()

toBilevelBitmap(
   colorChannel?, 
   lowerBitsFirst?, 
   whiteIsZero?): BilevelBitmap;

Creates a BilevelBitmap from the current Bitmap. This method does not perform any transformations of the color palette. It is expected that the source Bitmap has already been converted to bi-level palette using some thresholding or dithering effects. The toBilevelBitmap method just copies data from a specified color channel to a new instance of the BilevelBitmap class.

Parameters

colorChannel?

ColorChannel

The color channel used as the source of the bi-level data.

lowerBitsFirst?

boolean

If true, pixels are arranged within a byte such that pixels with lower column indices are stored in the lower-order bits of the byte.

whiteIsZero?

boolean

If true, indicates that 0 represents white and 1 represents black in the resulting BilevelBitmap.

Returns

BilevelBitmap

A new instance of BilevelBitmap.


toGrayscaleBitmap()

toGrayscaleBitmap(colorChannel?, whiteIsZero?): GrayscaleBitmap;

Creates a GrayscaleBitmap from the current Bitmap. This method does not perform any transformations of the color palette. It is expected that the source Bitmap has already been converted to grayscale palette using the Bitmap#applyGrayscaleEffect or something like that. Alternatively, you can use this method to extract individual channels of a color image without any prior conversion, and treat the resulting GrayscaleBitmap simply as a representation of some image data with 8 bits per pixel. The toGrayscaleBitmap method just copies data from a specified color channel to a new instance of the GrayscaleBitmap class.

Parameters

colorChannel?

ColorChannel

The color channel used as the source of grayscale data.

whiteIsZero?

boolean

If true, indicates that 0 represents white and 255 represents black in the resulting GrayscaleBitmap.

Returns

GrayscaleBitmap

A new instance of GrayscaleBitmap.