D2DBitmap
D2DBitmap(arg)
Parameters
| Name | Type | Description |
|---|---|---|
arg | D2DBitmap |
D2DBitmap(arg)
| Name | Type | Description |
|---|---|---|
arg | D2DBitmap |
Height: number
Width: number
ApplyAlpha(alpha)
| Name | Type | Description |
|---|---|---|
alpha | number | Valid values 0-255. |
ApplyAlphaIndirect(alpha)
Apllies alpha for entire image. Unlike D2DBitmap#ApplyAlpha changes the current object
| Name | Type | Description |
|---|---|---|
alpha | number | Valid values 0-255. |
ApplyMask(img)
Changes will be saved in the current bitmap.
| Name | Type | Description |
|---|---|---|
img | D2DBitmap |
Clone(x, y, w, h)
Create partial copy of image represented by D2DBitmap object
| Name | Type | Description |
|---|---|---|
x | number | |
y | number | |
w | number | |
h | number |
CreateRawBitmap()
Create clone bitmap from D2DBitmap object
GetColourScheme(max_count)
Returns up to max_count representative colours found in the image.
This is a legacy colour extraction method. For colour frequency information and more advanced clustering, use GetColourSchemeJSON or GetColourSchemeJSONV2.
| Name | Type | Description |
|---|---|---|
max_count | number | maximum number of colours to return |
Array<number>GetColourSchemeJSON(max_count)
Extracts representative colours from the image using K-means clustering in the RGB colour space.
Returns a JSON array in string form so you need to use JSON.parse() on the result.
Each entry contains a colour and its relative frequency in the clustered image.
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.
| Name | Type | Description |
|---|---|---|
max_count | number | maximum number of colours to return |
string// See docs\Helpers.js for "toRGB" function.
img = ... // use utils.GetAlbumArtV2 / gdi.Image / etc
colours = JSON.parse(img.GetColourSchemeJSON(5));
console.log(colours[0].col); // 4290772992
console.log(colours[0].freq); // 0.34
console.log(toRGB(colours[0].col)); // [192, 0, 0]
GetColourSchemeJSONV2(max_count, min_chroma)
Extracts representative colours from the image using K-means++ clustering in the Oklab colour space.
Returns a JSON array in string form so you need to use JSON.parse() on the result.
Each entry contains a colour and its relative frequency in the clustered image.
K-means++ initialization improves the distribution of the initial cluster centres, while Oklab provides a perceptually more uniform distance metric than RGB.
The optional min_chroma parameter limits the initial cluster centre selection to pixels with at least the specified Oklab chroma. It does not filter pixels or colours from the clustering result.
| Name | Type | Description |
|---|---|---|
max_count | number | maximum number of colours to return |
min_chroma = 0.0optional | number | minimum Oklab chroma for pixels used as initial cluster centres |
string// See docs\Helpers.js for "toRGB" function.
img = ... // use utils.GetAlbumArtV2 / gdi.Image / etc
colours = JSON.parse(img.GetColourSchemeJSONV2(10, 0.02));
console.log(colours[0].col); // 4290772992
console.log(colours[0].freq); // 0.34
console.log(toRGB(colours[0].col)); // [192, 0, 0]
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.
GetPixelData(format)
Extract raw pixels from bitmap as a byte array in specified pixel format
| Name | Type | Description |
|---|---|---|
format = "bgra32"optional | string | Pixel format string (default: "bgra32") Supported formats: |
Uint8Array — null if was an error (for example, bitmap in unsupported format or unsupported format specified)
InvertColours()
Inverts the colours in a bitmap, to create a negative image. i.e. White becomes black, black becomes white, etc.
ReleaseGraphics(gr)
| Name | Type | Description |
|---|---|---|
gr | D2DGraphics |
numberResize(w, h, mode)
| Name | Type | Description |
|---|---|---|
w | number | |
h | number | |
mode = 0optional | number |
ResizeIndirect(w, h, mode)
Resizes image. Unlike D2DBitmap#Resize changes the current object
| Name | Type | Description |
|---|---|---|
w | number | |
h | number | |
mode = 0optional | number | |
sharpness = 0.0optional | number | |
border_hard = falseoptional | number | |
cx = 0optional | number | Scale center point x |
cy = 0optional | number | Scale center point y |
RotateFlip(mode)
Changes will be saved in the current bitmap.
| Name | Type | Description |
|---|---|---|
mode | number | See RotateFlipType |
SaveAs(path, format)
| Name | Type | Description |
|---|---|---|
path | string | Full path including file extension. The parent folder must already exist. |
format = 'image/png'optional | string | "image/png" |
booleanlet img = utils.GetAlbumArtEmbedded(fb.GetFocusItem().RawPath, 0);
if (img) {
img.SaveAs("D:\\export.jpg", "image/jpeg");
}
StackBlur(radius)
Changes will be saved in the current bitmap.
| Name | Type | Description |
|---|---|---|
radius | number | Valid values 2-254. |
<caption>Blur image<caption>
// `samples/basic/StackBlur (image).js`<caption>Blur text<caption>
// `samples/basic/StackBlur (text).js`