Trait clipboard_rs::common::RustImage
source · pub trait RustImage: Sized {
// Required methods
fn empty() -> Self;
fn is_empty(&self) -> bool;
fn from_path(path: &str) -> Result<Self>;
fn from_bytes(bytes: &[u8]) -> Result<Self>;
fn get_size(&self) -> (u32, u32);
fn thumbnail(&self, width: u32, height: u32) -> Result<Self>;
fn resize(
&self,
width: u32,
height: u32,
filter: FilterType
) -> Result<Self>;
fn to_jpeg(&self, quality: u8) -> Result<RustImageBuffer>;
fn to_png(&self) -> Result<RustImageBuffer>;
fn to_bitmap(&self) -> Result<RustImageBuffer>;
fn save_to_path(&self, path: &str) -> Result<()>;
}Required Methods§
fn is_empty(&self) -> bool
sourcefn from_bytes(bytes: &[u8]) -> Result<Self>
fn from_bytes(bytes: &[u8]) -> Result<Self>
Create a new image from a byte slice
sourcefn thumbnail(&self, width: u32, height: u32) -> Result<Self>
fn thumbnail(&self, width: u32, height: u32) -> Result<Self>
Scale this image down to fit within a specific size.
Returns a new image. The image’s aspect ratio is preserved.
The image is scaled to the maximum possible size that fits
within the bounds specified by nwidth and nheight.
This method uses a fast integer algorithm where each source pixel contributes to exactly one target pixel. May give aliasing artifacts if new size is close to old size.
sourcefn resize(&self, width: u32, height: u32, filter: FilterType) -> Result<Self>
fn resize(&self, width: u32, height: u32, filter: FilterType) -> Result<Self>
en: Adjust the size of the image without retaining the aspect ratio zh: 调整图片大小,不保留长宽比
sourcefn to_jpeg(&self, quality: u8) -> Result<RustImageBuffer>
fn to_jpeg(&self, quality: u8) -> Result<RustImageBuffer>
en: Convert image to jpeg format, quality is the quality, give a value of 0-100, 100 is the highest quality, the returned image is a new image, and the data itself will not be modified zh: 把图片转为 jpeg 格式,quality(0-100) 为质量,输出字节数组,可直接通过 io 写入文件
sourcefn to_png(&self) -> Result<RustImageBuffer>
fn to_png(&self) -> Result<RustImageBuffer>
en: Convert to png format, the returned image is a new image, and the data itself will not be modified zh: 转为 png 格式,返回的为新的图片,本身数据不会修改