pub enum ImageFormat {
Png,
Jpeg,
Webp,
Gif,
Bmp,
Tiff,
Heif,
Unknown,
}Expand description
An encoded image format: what BitmapInfo::format reports and EncodeSpec::format asks
for. Not every backend encodes every one: ask Toolkit::encode_formats (the
Cap::ImageEncode pair of Toolkit::font_families/Cap::FontList) rather than
assuming.
Variants§
Png
Jpeg
Webp
Gif
Bmp
Tiff
Heif
HEIF/HEIC, Apple’s camera format; decodable on the Apple backends and Android, and encodable almost nowhere.
Unknown
Decoded from bytes whose magic numbers ImageFormat::sniff does not know. A backend may
still decode it: the platform decoders read more formats than Day names.
Implementations§
Source§impl ImageFormat
impl ImageFormat
Sourcepub fn mime(self) -> &'static str
pub fn mime(self) -> &'static str
The IANA media type, which is also the string the ArkUI packer, GDI+ and the browser’s
toBlob take. Unknown answers application/octet-stream.
Sourcepub fn dimensions(bytes: &[u8]) -> Option<(u32, u32)>
pub fn dimensions(bytes: &[u8]) -> Option<(u32, u32)>
The pixel size the encoded bytes declare, read from the container’s own header (docs/images.md).
Every backend that decodes natively reports its own dimensions; this exists for the one
that cannot. The XAML backend’s (windows-winui) BitmapImage learns its size
asynchronously, only once the element has been shown, so a synchronous image_info there
would have nothing to say.
Reading the header instead gives the same answer the decoder would, before any decoding.
None when the header is absent, truncated, or a container this does not parse.
Sourcepub fn sniff(bytes: &[u8]) -> Option<ImageFormat>
pub fn sniff(bytes: &[u8]) -> Option<ImageFormat>
The format bytes begins with, by magic number: enough to fill BitmapInfo::format
on every backend, including the ones whose decoder never says what it decoded.
Hand-rolled rather than a crate: it is a dozen byte comparisons against fixed prefixes, and the alternative is an image-decoding dependency in the one crate that must stay dependency-free.
Trait Implementations§
Source§impl Clone for ImageFormat
impl Clone for ImageFormat
Source§fn clone(&self) -> ImageFormat
fn clone(&self) -> ImageFormat
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more