Skip to main content

LensStudio:Ui.Pixmap

Class

Represents an image in memory.

Index

Example

export class PixmapPanel extends PanelPlugin {
connections: any[];
static descriptor() {
const d = new Descriptor();
d.id = 'com.docs.UiPixmapExample';
d.name = 'Pixmap Example';
d.defaultDockState = DockState.Detached;
d.defaultSize = new Size(350, 300);
return d;
}
constructor(pluginSystem: Editor.PluginSystem, descriptor?: Descriptor) {
super(pluginSystem, descriptor);
this.connections = [];
}
createWidget(parent: Widget): Widget {
const root = new Widget(parent);
const layout = new BoxLayout();
layout.setDirection(Direction.TopToBottom);
layout.spacing = 8;
root.layout = layout;

const title = new Label(root);
title.text = 'Pixmap Demo';
title.fontRole = FontRole.TitleBold;
layout.addWidget(title);

// Pixmap holds a pixel image for UI display
const pixmap = new Pixmap(new Editor.Path('icon.png'));
pixmap.resize(64, 64);

const info = new Label(root);
info.text = 'Pixmap size: ' + pixmap.width + 'x' + pixmap.height;
layout.addWidget(info);

// Display the pixmap in an ImageView
const imageView = new ImageView(root);
imageView.pixmap = pixmap;
imageView.scaledContents = true;
imageView.setFixedWidth(64);
imageView.setFixedHeight(64);
layout.addWidget(imageView);

return root;
}
deinit(): void {
this.connections.forEach((c: any) => c?.disconnect());
this.connections = [];
}
}

Extends

Constructors

Constructor

new Pixmap(filename): Pixmap

Constructs a new Pixmap instance for use in UI widgets.

Parameters

ParameterType
filenamePath

Returns

Pixmap

Overrides

ScriptObject.constructor

Properties

aspectRatioMode

aspectRatioMode: AspectRatioMode

Controls how the aspect ratio is preserved during resize operations.


height

height: number

Height of the pixmap in pixels.


transformationMode

transformationMode: TransformationMode

Controls the transformation quality mode used when scaling the pixmap.


width

width: number

Width of the pixmap in pixels.

Methods

crop()

crop(rect): void

Crops the pixmap to the specified rectangle.

Parameters

ParameterType
rectRect

Returns

void


getTypeName()

static getTypeName(): string

Returns the type name of this class.

Returns

string

Overrides

ScriptObject.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

ScriptObject.getTypeName


isOfType()

isOfType(type): boolean

Returns true if the object is of the specified type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

ScriptObject.isOfType


isSame()

isSame(other): boolean

Returns true if this object refers to the same instance as the given object.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

ScriptObject.isSame


load()

load(filename): void

Loads an image from the given file path.

Parameters

ParameterType
filenamePath

Returns

void


resize()

resize(width, height): void

Resizes the pixmap to the specified width and height.

Parameters

ParameterType
widthnumber
heightnumber

Returns

void


save()

save(filename, quality?): void

Saves the pixmap to the given file path, with optional quality setting.

Parameters

ParameterType
filenamePath
quality?number

Returns

void