Skip to main content

LensStudio:Preview.Image

Class

Frame captured from a preview by screenshot() or tryScreenshot().

Index

Example

Capture a preview frame, save it as a PNG file, and return the encoded bytes, for example to attach to a report. Saving requires the filesystem permission.

import { LensPreview } from 'LensStudio:LensPreview';

export async function captureFrame(preview: LensPreview, pngFile: Editor.Path): Promise<Uint8Array> {
const image = await preview.tryScreenshot(20000);
console.log(`Captured a ${image.width}x${image.height} preview frame`);
image.save(pngFile); // the format follows the file extension
return image.toBytes(); // PNG unless another format is given
}

Extends

Properties

height

readonly height: number

Height of the image in pixels.


width

readonly width: number

Width of the image in pixels.

Methods

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


save()

save(filename): void

Saves the image to the given file path, using the image format that matches the file extension. Requires the filesystem permission.

Parameters

ParameterType
filenamePath

Returns

void


scaledToFit()

scaledToFit(width, height): Image

Parameters

ParameterType
widthnumber
heightnumber

Returns

Image


toBytes()

toBytes(format?): Uint8Array

Parameters

ParameterType
format?string

Returns

Uint8Array