Image
使用保留式图像资源显示文件系统路径、文件 URL 或 base64 数据 URL。
正在加载交互演示…
img(Image::from_rgba(128, 128, pixels).expect("image"))
.size(160.0, 160.0)
.rounded(12.0)#导入
从 quickgui 导入 Image。
use quickgui::*;#用法
img(Image::from_rgba(128, 128, pixels).expect("image"))
.size(160.0, 160.0)
.rounded(12.0)#API 参考
展开条目查看说明和完整签名。短横线表示声明中未记录默认值。
Image
查看源码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.
decodepub 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`.
pub fn decode(encoded: impl AsRef<[u8]>) -> Result<Self, ImageError>查看源码openpub 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 open(path: impl AsRef<Path>) -> Result<Self, ImageError>查看源码widthpub fn width(&self) -> u32—
heightpub fn height(&self) -> u32—
sizepub fn size(&self) -> Size—
byte_lenpub fn byte_len(&self) -> usize—
rgbapub fn rgba(&self) -> &[u8]—
from_data_urlpub 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`].
pub fn from_data_url(url: &str) -> Result<Self, ImageError>查看源码named_systempub 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`].
pub fn named_system(name: &str) -> Result<Self, ImageError>查看源码named_system_sizedpub 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.
pub fn named_system_sized(name: &str, point_size: f32, scale: f32) -> Result<Self, ImageError>查看源码templatepub 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.
pub fn template(&self, template: bool) -> Self查看源码is_templatepub fn is_template(&self) -> bool—
with_representationspub 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`].
pub fn with_representations( &self, representations: impl IntoIterator<Item = (f32, Self)>, ) -> Result<Self, ImageError>查看源码representationspub fn representations(&self) -> &[(f32, Self)]—
Additional backing-scale representations attached to this image.
pub fn representations(&self) -> &[(f32, Self)]查看源码resizepub fn resize(&self, width: u32, height: u32) -> Result<Self, ImageError>—
Resample this image to exact pixel dimensions with a bilinear filter.
pub fn resize(&self, width: u32, height: u32) -> Result<Self, ImageError>查看源码croppub 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.
pub fn crop(&self, bounds: Rect) -> Result<Self, ImageError>查看源码to_pngpub fn to_png(&self) -> Result<Vec<u8>, ImageError>—
Encode this image as PNG with its alpha channel intact.
pub fn to_png(&self) -> Result<Vec<u8>, ImageError>查看源码to_jpegpub fn to_jpeg(&self, quality: u8) -> Result<Vec<u8>, ImageError>—
Encode this image as JPEG at `quality` (1-100), compositing away the alpha channel. JPEG has no alpha, so translucent pixels are composited over opaque white.
pub fn to_jpeg(&self, quality: u8) -> Result<Vec<u8>, ImageError>查看源码img
查看源码pub fn img(source: impl Into<ImageSource>) -> ElementCreate an image element with intrinsic sizing and `object-fit: contain` behavior.
