Documentation/D2DBitmap
class

D2DBitmap

js/d2d.js:1
D2DBitmap(arg)

Parameters

NameTypeDescription
argD2DBitmap
propertyreadonly

Height

js/d2d.js:7
Height: number
propertyreadonly

Width

js/d2d.js:13
Width: number
method

ApplyAlpha

js/d2d.js:19
ApplyAlpha(alpha)

Parameters

NameTypeDescription
alphanumber

Valid values 0-255.

Returns

D2DBitmap
method

ApplyAlphaIndirect

js/d2d.js:25
ApplyAlphaIndirect(alpha)

Apllies alpha for entire image. Unlike D2DBitmap#ApplyAlpha changes the current object

Parameters

NameTypeDescription
alphanumber

Valid values 0-255.

method

ApplyMask

js/d2d.js:31
ApplyMask(img)

Changes will be saved in the current bitmap.

Parameters

NameTypeDescription
imgD2DBitmap

Example source

method

Clone

js/d2d.js:40
Clone(x, y, w, h)

Create partial copy of image represented by D2DBitmap object

Parameters

NameTypeDescription
xnumber
ynumber
wnumber
hnumber

Returns

D2DBitmap
method

CreateRawBitmap

js/d2d.js:51
CreateRawBitmap()

Create clone bitmap from D2DBitmap object

Returns

D2DBitmap
method

GetColourScheme

js/d2d.js:58
GetColourScheme(max_count)

Takes the top of colors found in the image

Parameters

NameTypeDescription
max_countnumber

Returns

Array<number>
method

GetColourSchemeJSON

js/d2d.js:65
GetColourSchemeJSON(max_count)

Returns a JSON array in string form so you need to use JSON.parse() on the result.
Each entry in the array is an object which contains colour and frequency values.
Uses a different method for calculating colours than GetColourScheme.
Image is automatically resized during processing for performance reasons so there's no need to resize before calling the method.

Parameters

NameTypeDescription
max_countnumber

Returns

string

Example

// See docs\Helpers.js for "toRGB" function.
img = ... // use utils.GetAlbumArtV2 / d2d.Image / etc
colours = JSON.parse(img.GetColourSchemeJSON(5));
console.log(colours[0].col); // -4194304
console.log(colours[0].freq); // 0.34
console.log(toRGB(colours[0].col)); // [192, 0, 0]
method

GetColourSchemeJSONV2

js/d2d.js:85
GetColourSchemeJSONV2(max_count)

Returns a JSON array in string form so you need to use JSON.parse() on the result.
Each entry in the array is an object which contains colour and frequency values.
Uses a different method than GetColourSchemeJSON for calculating colours (K-means++ with Oklab).

Parameters

NameTypeDescription
max_countnumber
min_chroma = 0.0optionalnumber

minimal chroma value for choosing start cluster pixel

Returns

string
method

GetGraphics

js/d2d.js:96
GetGraphics()

IMPORTANT: You MUST call ReleaseGraphics after work on D2DGraphics is done!
It is illegal to call any methods of D2DBitmap object while working with the obtained D2DGraphics object until ReleaseGraphics is called.

Returns

D2DGraphics
method

GetPixelData

js/d2d.js:104
GetPixelData(format)

Extract raw pixels from bitmap as a byte array in specified pixel format

Parameters

NameTypeDescription
format = "bgra32"optionalstring

Pixel format string (default: "bgra32") Supported formats:
"bgra32" 32bpp BGRA
"rgba32" 32bpp RGBA
"bgr24" 24bpp BGR
"rgb24" 24bpp RGB

Returns

Uint8Array

null if was an error (for example, bitmap in unsupported format or unsupported format specified)

Example source

method

InvertColours

js/d2d.js:119
InvertColours()

Inverts the colours in a bitmap, to create a negative image. i.e. White becomes black, black becomes white, etc.

Returns

D2DBitmap
method

ReleaseGraphics

js/d2d.js:126
ReleaseGraphics(gr)

Parameters

NameTypeDescription
grD2DGraphics

Returns

number
method

Resize

js/d2d.js:132
Resize(w, h, mode)

Parameters

NameTypeDescription
wnumber
hnumber
mode = 0optionalnumber

See InterpolationMode

Returns

D2DBitmap
method

ResizeIndirect

js/d2d.js:140
ResizeIndirect(w, h, mode)

Resizes image. Unlike D2DBitmap#Resize changes the current object

Parameters

NameTypeDescription
wnumber
hnumber
mode = 0optionalnumber

See InterpolationMode

sharpness = 0.0optionalnumber
border_hard = falseoptionalnumber
cx = 0optionalnumber

Scale center point x

cy = 0optionalnumber

Scale center point y

method

RotateFlip

js/d2d.js:152
RotateFlip(mode)

Changes will be saved in the current bitmap.

Parameters

NameTypeDescription
modenumber

See RotateFlipType

method

SaveAs

js/d2d.js:159
SaveAs(path, format)

Parameters

NameTypeDescription
pathstring

Full path including file extension. The parent folder must already exist.

format = 'image/png'optionalstring

"image/png"
"image/bmp"
"image/jpeg"
"image/gif"
"image/tiff"

Returns

boolean

Example

let img = utils.GetAlbumArtEmbedded(fb.GetFocusItem().RawPath, 0);
if (img) {
    img.SaveAs("D:\\export.jpg", "image/jpeg");
}
method

StackBlur

js/d2d.js:177
StackBlur(radius)

Changes will be saved in the current bitmap.

Parameters

NameTypeDescription
radiusnumber

Valid values 2-254.

Examples

<caption>Blur image<caption>
// `samples/basic/StackBlur (image).js`
<caption>Blur text<caption>
// `samples/basic/StackBlur (text).js`