Skip to main content
Version: 0.2.3

Interface: Image

ImageModule.Image

An Image object in JavaScript is a reference to a native image object wrapped in NativeJSRef. The image data is not transferred over the React Native Bridge, but it offers functions to manipulate the image. All functions are executed async in native.

info

Eventually, this will change with the introduction of the new React Native architecture including JSI, Fabric, and TurboModules.

Hierarchy

Properties

ID

ID: string

The internal ID for the object instance in native. Instead of serializing the object in native and sending it via the React Native Bridge, each native object will be assigned an ID which is sent to JavaScript instead. The ID will be used to reference the native object instance when calling functions on the JavaScript object.

Inherited from

NativeJSRef.ID

Methods

getHeight

getHeight(): number

Get the height of an image (in pixel).

Returns

number


getNaturalHeight

getNaturalHeight(): number

Get the natural height of an image (in pixel).

Returns

number


getNaturalWidth

getNaturalWidth(): number

Get the natural width of an image (in pixel).

Returns

number


getPixelDensity

getPixelDensity(): number

Get the pixel density for this image. The width and height multiplied by the pixelDensity is naturalWidth and naturalHeight.

Returns

number


getWidth

getWidth(): number

Get the width of an image (in pixel).

Returns

number


release

release(): Promise<void>

Until explicitly released, an Image will have a reference in memory. Not calling Image.release can eventually result in an OutOfMemoryException.

caution

While this is an async function, it does not need to be awaited. For example, the GC on Android will eventually free the allocated memory.

Returns

Promise<void>


scale

scale(sx, sy): Promise<Image>

The Image.scale method of the Image API adds a scaling transformation horizontally and/or vertically. For instance, a scaling factor of 0.5 results in a unit size of 0.5 pixels; the image is thus at half the normal size. Similarly, a scaling factor of 2.0 increases the unit size so that one unit becomes two pixels; images are thus at twice the normal size.

The method will apply the scaling on a copy of the Image and return the scaled Image asynchronously.

Parameters

NameTypeDescription
sxnumberScaling factor in the horizontal direction. A negative value flips pixels across the vertical axis. A value of 1 results in no horizontal scaling.
synumberScaling factor in the vertical direction. A negative value flips pixels across the horizontal axis. A value of 1 results in no vertical scaling.

Returns

Promise<Image>