Trait RustImage

Source
pub trait RustImage: Sized {
Show 14 methods // 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 from_dynamic_image(image: DynamicImage) -> 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 encode_image( &self, target_color_type: ColorType, format: ImageFormat, ) -> Result<RustImageBuffer>; fn to_jpeg(&self) -> Result<RustImageBuffer>; fn to_png(&self) -> Result<RustImageBuffer>; fn save_to_path(&self, path: &str) -> Result<()>; fn get_dynamic_image(&self) -> Result<DynamicImage>; fn to_rgba8(&self) -> Result<RgbaImage>;
}

Required Methods§

Source

fn empty() -> Self

create an empty image

Source

fn is_empty(&self) -> bool

Source

fn from_path(path: &str) -> Result<Self>

Read image from file path

Source

fn from_bytes(bytes: &[u8]) -> Result<Self>

Create a new image from a byte slice

Source

fn from_dynamic_image(image: DynamicImage) -> Self

Source

fn get_size(&self) -> (u32, u32)

width and height

Source

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.

Source

fn resize(&self, width: u32, height: u32, filter: FilterType) -> Result<Self>

en: Adjust the size of the image without retaining the aspect ratio zh: 调整图片大小,不保留长宽比

Source

fn encode_image( &self, target_color_type: ColorType, format: ImageFormat, ) -> Result<RustImageBuffer>

Source

fn to_jpeg(&self) -> Result<RustImageBuffer>

Source

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 格式,返回的为新的图片,本身数据不会修改

Source

fn save_to_path(&self, path: &str) -> Result<()>

Source

fn get_dynamic_image(&self) -> Result<DynamicImage>

Source

fn to_rgba8(&self) -> Result<RgbaImage>

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§