Documentation/gdi
namespaceWORKER

gdi

js/foo_uie_jsplitter.js:1481

DrawMode-aware graphics facade. With window.DrawMode == 0 its resource factories use GDI+; with window.DrawMode == 1 they create the corresponding Direct2D resources instead. A Worker uses the DrawMode captured when that Worker is created, so the same gdi.* calls match the parent panel graphics backend.

methodWORKER

Brush

js/foo_uie_jsplitter.js:1489
Brush(type, param1, param2, param3, param4)

Creates a drawing brush of the specified type. The meaning of the brush's input parameters depends on its type.
For type == BrushType.Solid:
- param1: brush colour in ARGB
For type == BrushType.LinearGradient:
- param1: start point coords of linear gradient in form of Array(2) (for ex.: [0, 0])
- param2: end point coords of linear gradient in form of Array(2) (for ex.: [100, 0])
- param3: gradient stops specified as an array with alternating position and color values for each stop (for ex.: [0.0, 0xFF000000, 0.5, 0xFFFF0000, 1.0, 0xFFFFFFFF])
- param4: wrap mode responsible for how the gradient is repeated when drawing. See BrushWrapMode. Default is BrushWrapMode.Tile
For type == BrushType.RadialGradient:
- param1: center point coords of radial gradient in form of Array(2) (for ex.: [50, 50])
- param2: radius values for X and Y axes in form of Array(2) (for ex.: [50, 50])
- param3: gradient stops specified as an array with alternating position and color values for each stop (for ex.: [0.0, 0xFF000000, 0.5, 0xFFFF0000, 1.0, 0xFFFFFFFF])
- param4: wrap mode responsible for how the gradient is repeated when drawing. See BrushWrapMode. Default is BrushWrapMode.Tile
For type == BrushType.Bitmap:
- param1: GdiBitmap object used for drawing by brush
- param2: wrap mode responsible for how the image is repeated when drawing. See BrushWrapMode

Parameters

NameTypeDescription
typeBrushType
param1*
param2 = undefinedoptional*
param3 = undefinedoptional*
param4 = undefinedoptional*

Returns

GdiBrush —

Brush object used in Draw/Fill methods

Throws

Error —

If the brush parameters are invalid, including malformed points, radius values, gradient stops, or bitmap input.

Example source

methodWORKER

CreateImage

js/foo_uie_jsplitter.js:1520
CreateImage(w, h)

Parameters

NameTypeDescription
wnumber
hnumber

Returns

GdiBitmap
methodWORKER

CreateImageFromPixelData

js/foo_uie_jsplitter.js:1528
CreateImageFromPixelData(pixelData, width, height, format = "bgra32")

Create GdiBitmap from raw pixel data in memory.

Parameters

NameTypeDescription
pixelDataUint8Array

Raw pixel bytes

widthnumber

Image width in pixels

heightnumber

Image height in pixels

format = "bgra32"optionalstring

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

Returns

GdiBitmap —

null if was an error (for example pixelData array length is not suitable for the specified parameters)

Throws

Error —

If data is not a non-empty Uint8Array.

Example source

methodWORKER

Font

js/foo_uie_jsplitter.js:1548
Font(name, size_px, style)

Performance note: avoid using inside on_paint.
Performance note II: try caching and reusing GdiFont objects, since the maximum amount of such objects is hard-limited by Windows. GdiFont creation will fail after reaching this limit.

Parameters

NameTypeDescription
namestring
size_pxnumber

See Point2Pixel function for conversions

style = 0optionalnumber

See FontStyle flags

Returns

?GdiFont —

null, if font is not present.

methodWORKER

Image

js/foo_uie_jsplitter.js:1562
Image(path)

Load image from file.

Performance note: consider using gdi.LoadImageAsync or gdi.LoadImageAsyncV2 if there are a lot of images to load or if the image is big.

Relative filesystem paths are resolved as described in utils.ReadTextFile.

Parameters

NameTypeDescription
pathstring

Returns

?GdiBitmap —

null, if image failed to load.

Example

let img = gdi.Image('e:\\images folder\\my_image.png');
methodWORKER

LoadImageAsync

js/foo_uie_jsplitter.js:1579
LoadImageAsync(window_id, path)

Load image from file asynchronously.

Relative filesystem paths are resolved as described in utils.ReadTextFile.

Parameters

NameTypeDescription
window_idnumber

unused

pathstring

Returns

number —

a unique id, which is used in on_load_image_done.

Throws

Error —

If the panel host is unavailable or foobar2000 is not fully initialized.

Example source

methodWORKER

LoadImageAsyncV2

js/foo_uie_jsplitter.js:1594
LoadImageAsyncV2(window_id, path)

Load image from file asynchronously. Returns a Promise object, which will be resolved when image loading is done.

Relative filesystem paths are resolved as described in utils.ReadTextFile.

Parameters

NameTypeDescription
window_idnumber

unused

pathstring

Returns

Promise.<?GdiBitmap>

Throws

Error —

If the panel host is unavailable or foobar2000 is not fully initialized.

Example source

methodWORKER

LoadSVG

js/foo_uie_jsplitter.js:1610
LoadSVG(path_or_xml, max_width)

Loads rasterized image from SVG file or XML string

Relative filesystem paths are resolved as described in utils.ReadTextFile. Raw SVG/XML strings are used as-is.

Parameters

NameTypeDescription
path_or_xmlstring

string containing SVG file path or raw XML

max_width = 0optionalnumber

If specified rasterizes with width = max_width and height according to the proportions, otherwise uses "width" and "height" attributes in SVG header if exist

Returns

?GdiBitmap —

Rasterized bitmap, null in case of error

Example

const svg_file = fb.ComponentPath + 'samples\\svg\\android.svg';

const original = gdi.LoadSVG(svg_file);
const large = gdi.LoadSVG(svg_file, 512); // set optional max_width

function on_paint(gr) {
    gr.DrawImage(original, 0, 0, original.Width, original.Height, 0, 0, original.Width, original.Height);
    gr.DrawImage(large, original.Width, 0, large.Width, large.Height, 0, 0, large.Width, large.Height);
}