fix(clipboard-manager): `read_image` wrongly set the image rgba data with binary PNG data.

pull/1986/head
Rika 9 months ago
parent 1f649c7f1f
commit d13444b5ea
No known key found for this signature in database

@ -3,7 +3,6 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
use arboard::ImageData; use arboard::ImageData;
use image::ImageEncoder;
use serde::de::DeserializeOwned; use serde::de::DeserializeOwned;
use tauri::{image::Image, plugin::PluginApi, AppHandle, Runtime}; use tauri::{image::Image, plugin::PluginApi, AppHandle, Runtime};
@ -85,16 +84,7 @@ impl<R: Runtime> Clipboard<R> {
match &self.clipboard { match &self.clipboard {
Ok(clipboard) => { Ok(clipboard) => {
let image = clipboard.lock().unwrap().get_image()?; let image = clipboard.lock().unwrap().get_image()?;
let image = Image::new_owned(image.bytes.to_vec(), image.width as u32, image.height as u32);
let mut buffer: Vec<u8> = Vec::new();
image::codecs::png::PngEncoder::new(&mut buffer).write_image(
&image.bytes,
image.width as u32,
image.height as u32,
image::ExtendedColorType::Rgba8,
)?;
let image = Image::new_owned(buffer, image.width as u32, image.height as u32);
Ok(image) Ok(image)
} }
Err(e) => Err(crate::Error::Clipboard(e.to_string())), Err(e) => Err(crate::Error::Clipboard(e.to_string())),

Loading…
Cancel
Save