跳到内容
Tauri

image

图像

一个从上到下按行优先顺序排列的 RGBA 图像。

继承自

访问器

rid
获取签名
get rid(): number
返回值

number

继承自

Resource.rid

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/core.ts#L286

方法

close()
close(): Promise<void>

销毁并从内存中清理此资源。你不应再在此对象上调用任何方法,并且应放弃对其的所有引用。

返回值

Promise<void>

继承自

Resource.close

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/core.ts#L298

rgba()
rgba(): Promise<Uint8Array<ArrayBufferLike>>

返回此图像的 RGBA 数据,从上到下按行优先顺序排列。

返回值

Promise<Uint8Array<ArrayBufferLike>>

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/image.ts#L79

size()
size(): Promise<ImageSize>

返回此图像的大小。

返回值

Promise<ImageSize>

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/image.ts#L86

fromBytes()
static fromBytes(bytes): Promise<Image>

通过推断文件格式,使用提供的字节创建一个新图像。如果格式已知,请优先使用 [@link Image.fromPngBytes] 或 [@link Image.fromIcoBytes]。

仅支持 icopng 格式(基于激活的功能标志)。

请注意,你需要 image-icoimage-png Cargo 功能才能使用此 API。要启用它,请更改你的 Cargo.toml 文件

[dependencies]
tauri = { version = "...", features = ["...", "image-png"] }
参数
参数类型
bytesnumber[] | ArrayBuffer | Uint8Array<ArrayBufferLike>
返回值

Promise<Image>

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/image.ts#L52

fromPath()
static fromPath(path): Promise<Image>

使用提供的路径创建一个新图像。

仅支持 icopng 格式(基于激活的功能标志)。

请注意,你需要 image-icoimage-png Cargo 功能才能使用此 API。要启用它,请更改你的 Cargo.toml 文件

[dependencies]
tauri = { version = "...", features = ["...", "image-png"] }
参数
参数类型
pathstring
返回值

Promise<Image>

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/image.ts#L72

new()
static new(
rgba,
width,
height): Promise<Image>

使用 RGBA 数据创建一个新图像,从上到下按行优先顺序排列,并具有指定的宽度和高度。

参数
参数类型
rgbanumber[] | ArrayBuffer | Uint8Array<ArrayBufferLike>
widthnumber
heightnumber
返回值

Promise<Image>

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/image.ts#L27

接口

ImageSize

属性

属性类型定义于
heightnumberSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/image.ts#L12
widthnumberSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/image.ts#L10

函数

transformImage()

function transformImage<T>(image): T

将图像从各种类型转换为 Rust 可接受的类型。

有关更多信息,请参阅 tauri::image::JsImage。请注意,API 签名不稳定,可能会更改。

类型参数

类型参数
T

参数

参数类型
image| null | string | number[] | ArrayBuffer | Uint8Array<ArrayBufferLike> | Image

返回值

T

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/image.ts#L97


© 2025 Tauri 贡献者。CC-BY / MIT