tauri-apps / tauri-apps/plugins-workspace

How does clipboard manager's writeImage function work?

Open
#2,208 11 comments 0 reactions 0 assignees View on GitHub
plugin: clipboard-manager type: documentation
Dominant language
Rust
Stars
1.8k
Forks
602
Avg merge
4d 14h
Merged PRs (30d)
9

Description

If i try to write images like the example:

```ts
import { writeImage } from '@tauri-apps/plugin-clipboard-manager';
const buffer = [
// A red pixel
255, 0, 0, 255,

// A green pixel
0, 255, 0, 255,
];
await writeImage(buffer);
```

I get an error on the webview console
`Unhandled Promise Rejection: expected RGBA image data, found raw bytes`

If I try to convert an image to RGBA data in rust then pass the buffer I still get the same error
```rs
#[tauri::command(async)]
#[specta::specta]
pub fn image_path_to_rgba_bytes(path: &str) -> Vec {
let img = image::open(path).unwrap().to_rgba8();
img.into_raw()
}
```

```ts
const rawImage = await commands.imagePathToRgbaBytes(imagePath);
await writeImage(rawImage);
// Unhandled Promise Rejection: expected RGBA image data, found raw bytes
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.