pub struct Image(/* private fields */);Expand description
Immutable, cheap-to-clone RGBA image data.
Clones share both identity and pixels. That identity lets every window reuse one GPU texture until the renderer’s bounded cache needs the space for a newer visible image.
Implementations§
Source§impl Image
impl Image
Sourcepub fn from_rgba(
width: u32,
height: u32,
rgba: impl Into<Arc<[u8]>>,
) -> Result<Self, ImageError>
pub fn from_rgba( width: u32, height: u32, rgba: impl Into<Arc<[u8]>>, ) -> Result<Self, ImageError>
Construct an image from tightly packed, straight-alpha RGBA8 pixels.
Sourcepub fn decode(encoded: impl AsRef<[u8]>) -> Result<Self, ImageError>
pub fn decode(encoded: impl AsRef<[u8]>) -> Result<Self, ImageError>
Decode PNG, JPEG, TIFF, WebP, or the first frame of a GIF from memory.
Decoding is explicit and synchronous. Applications should perform it away from latency-
sensitive input handling and then publish the resulting cheap-to-clone Image.
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self, ImageError>
pub fn open(path: impl AsRef<Path>) -> Result<Self, ImageError>
Decode a supported image file synchronously with encoded and decoded size limits.
Prefer passing a path to crate::img for event-driven background loading. This method is
useful when an application already owns a background execution context.
Paths whose stem ends in Template, optionally followed by a scale suffix such as @2x,
are marked for macOS template rendering. Call Self::template to override that
convention.
pub fn width(&self) -> u32
pub fn height(&self) -> u32
pub fn size(&self) -> Size
pub fn byte_len(&self) -> usize
Sourcepub fn from_data_url(url: &str) -> Result<Self, ImageError>
pub fn from_data_url(url: &str) -> Result<Self, ImageError>
Decode a base64 data: URL carrying PNG, JPEG, GIF, or WebP bytes.
Only base64 payloads are accepted; percent-encoded data: URLs are rejected because the
binary formats QuickGUI decodes are never sent that way in practice. The URL text is
bounded by MAX_IMAGE_DATA_URL_BYTES and the decoded payload by the same limits as
Image::decode.
Sourcepub fn named_system(name: &str) -> Result<Self, ImageError>
pub fn named_system(name: &str) -> Result<Self, ImageError>
Rasterize a system-provided image at DEFAULT_SYSTEM_IMAGE_POINT_SIZE and
DEFAULT_SYSTEM_IMAGE_SCALE.
On macOS this resolves an NSImage name first and then an SF Symbol name. Other platforms
report ImageError::SystemImageUnavailable.
Sourcepub fn named_system_sized(
name: &str,
point_size: f32,
scale: f32,
) -> Result<Self, ImageError>
pub fn named_system_sized( name: &str, point_size: f32, scale: f32, ) -> Result<Self, ImageError>
Rasterize a system-provided image at a requested point size and backing scale.
The resulting bitmap is round(point_size * scale) pixels on its longest axis.
Sourcepub fn template(&self, template: bool) -> Self
pub fn template(&self, template: bool) -> Self
Return a copy marked as a macOS template image.
A template image is recolored by AppKit for the menu bar’s light, dark, and highlighted appearances using only its alpha channel. The returned value has a fresh identity so a renderer cache never confuses it with the untemplated original; the pixels are shared.
Sourcepub fn is_template(&self) -> bool
pub fn is_template(&self) -> bool
Whether this image is marked for macOS template rendering.
Sourcepub fn with_representations(
&self,
representations: impl IntoIterator<Item = (f32, Self)>,
) -> Result<Self, ImageError>
pub fn with_representations( &self, representations: impl IntoIterator<Item = (f32, Self)>, ) -> Result<Self, ImageError>
Attach additional backing-scale representations used when building a native image.
The receiver is the 1x representation. At most MAX_IMAGE_REPRESENTATIONS variants are
retained and each scale must lie between MIN_IMAGE_REPRESENTATION_SCALE and
MAX_IMAGE_REPRESENTATION_SCALE.
Sourcepub fn representations(&self) -> &[(f32, Self)]
pub fn representations(&self) -> &[(f32, Self)]
Additional backing-scale representations attached to this image.
Sourcepub fn resize(&self, width: u32, height: u32) -> Result<Self, ImageError>
pub fn resize(&self, width: u32, height: u32) -> Result<Self, ImageError>
Resample this image to exact pixel dimensions with a bilinear filter.
Sourcepub fn crop(&self, bounds: Rect) -> Result<Self, ImageError>
pub fn crop(&self, bounds: Rect) -> Result<Self, ImageError>
Copy a pixel rectangle out of this image.
The rectangle is rounded to whole pixels and must lie inside the image with a non-empty area.
Trait Implementations§
impl Eq for Image
Source§impl From<&Image> for ImageSource
impl From<&Image> for ImageSource
Source§impl From<Image> for ImageSource
impl From<Image> for ImageSource
Auto Trait Implementations§
impl Forget for Image
impl Freeze for Image
impl Move for Image
impl RefUnwindSafe for Image
impl Send for Image
impl Sync for Image
impl Unpin for Image
impl UnsafeUnpin for Image
impl UnwindSafe for Image
Blanket Implementations§
impl<T> Action for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.