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 moreimpl Copy for ImageFormat
Source§impl Debug for ImageFormat
impl Debug for ImageFormat
Source§impl Default for ImageFormat
impl Default for ImageFormat
Source§fn default() -> ImageFormat
fn default() -> ImageFormat
impl Eq for ImageFormat
Source§impl Hash for ImageFormat
impl Hash for ImageFormat
Source§impl PartialEq for ImageFormat
impl PartialEq for ImageFormat
impl StructuralPartialEq for ImageFormat
Auto Trait Implementations§
impl Freeze for ImageFormat
impl RefUnwindSafe for ImageFormat
impl Send for ImageFormat
impl Sync for ImageFormat
impl Unpin for ImageFormat
impl UnsafeUnpin for ImageFormat
impl UnwindSafe for ImageFormat
Blanket Implementations§
§impl<T> AnyEq for T
impl<T> AnyEq 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.impl<T> ErasedDestructor for Twhere
T: 'static,
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> ⓘ
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> ⓘ
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 more