pub struct Surface { /* private fields */ }Expand description
图片表面,用于存储和操作图片数据
Implementations§
Source§impl Surface
impl Surface
Sourcepub fn new(width: u32, height: u32) -> ImageResult<Self>
pub fn new(width: u32, height: u32) -> ImageResult<Self>
创建新的空白表面
Sourcepub fn new_with_color(
width: u32,
height: u32,
color: Rgba<u8>,
) -> ImageResult<Self>
pub fn new_with_color( width: u32, height: u32, color: Rgba<u8>, ) -> ImageResult<Self>
创建指定颜色的表面
Sourcepub fn from_file<P: AsRef<Path>>(path: P) -> ImageResult<Self>
pub fn from_file<P: AsRef<Path>>(path: P) -> ImageResult<Self>
从文件加载图片
Sourcepub fn from_bytes(data: &[u8]) -> ImageResult<Self>
pub fn from_bytes(data: &[u8]) -> ImageResult<Self>
从字节数据加载图片
Sourcepub fn from_rgba_image(image: RgbaImage) -> Self
pub fn from_rgba_image(image: RgbaImage) -> Self
从 RgbaImage 创建
Sourcepub fn to_png_bytes(&self) -> ImageResult<Vec<u8>>
pub fn to_png_bytes(&self) -> ImageResult<Vec<u8>>
保存为 PNG 格式的字节数据
Sourcepub fn to_jpeg_bytes(&self, quality: u8) -> ImageResult<Vec<u8>>
pub fn to_jpeg_bytes(&self, quality: u8) -> ImageResult<Vec<u8>>
保存为 JPEG 格式的字节数据
Sourcepub fn dimensions(&self) -> (u32, u32)
pub fn dimensions(&self) -> (u32, u32)
获取图片尺寸
Sourcepub fn resize(&self, width: u32, height: u32) -> ImageResult<Self>
pub fn resize(&self, width: u32, height: u32) -> ImageResult<Self>
调整图片大小
Sourcepub fn flip_horizontal(&self) -> Self
pub fn flip_horizontal(&self) -> Self
水平翻转
Sourcepub fn flip_vertical(&self) -> Self
pub fn flip_vertical(&self) -> Self
垂直翻转
Sourcepub fn clone_surface(&self) -> Self
pub fn clone_surface(&self) -> Self
克隆表面
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Surface
impl RefUnwindSafe for Surface
impl Send for Surface
impl Sync for Surface
impl Unpin for Surface
impl UnwindSafe for Surface
Blanket Implementations§
Source§impl<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere
Scheme: ApproxScheme,
impl<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere
Scheme: ApproxScheme,
Source§fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
Convert the given value into an approximately equivalent representation.
Source§impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Srcwhere
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Srcwhere
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
Source§type Err = <Dst as ApproxFrom<Src, Scheme>>::Err
type Err = <Dst as ApproxFrom<Src, Scheme>>::Err
The error type produced by a failed conversion.
Source§fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
Convert the subject into an approximately equivalent representation.
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, Dst> ConvAsUtil<Dst> for T
impl<T, Dst> ConvAsUtil<Dst> for T
Source§impl<T> ConvUtil for T
impl<T> ConvUtil for T
Source§fn approx_as<Dst>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst>,
fn approx_as<Dst>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst>,
Approximate the subject to a given type with the default scheme.
Source§fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>
fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>
Approximate the subject to a given type with a specific scheme.
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.