Struct ImageDecoder

Source
pub struct ImageDecoder {
    pub factory: *mut IWICImagingFactory,
}
Expand description

A image decoder. Can load an extended number of image file format from a filename, from a file handle, or from a stream.

ImageDecoder do not take any parameter to build, but it still provides a builder API to match the other component of NWG. You can also use “ImageDecoder::new” to avoid the builder API.

There’s not much reason to have more than 1 image decoder per application.

Images loaded from a decoder cannot be used as-is by an image frame. They must first be converted to a bitmap resource.

use native_windows_gui as nwg;
fn open_image(decoder: &nwg::ImageDecoder) -> Result<nwg::ImageData, nwg::NwgError> {
    decoder
        .from_filename("corn.png")?
        .frame(0)
}
use native_windows_gui as nwg;
fn build_image_decode(decode: &mut nwg::ImageDecoder) -> Result<(), nwg::NwgError> {
    nwg::ImageDecoder::builder()
        .build(decode)
}

Fields§

§factory: *mut IWICImagingFactory

Implementations§

Source§

impl ImageDecoder

Source

pub fn new() -> Result<ImageDecoder, NwgError>

Source

pub fn builder() -> ImageDecoderBuilder

Source

pub fn from_filename<'a>(&self, path: &'a str) -> Result<ImageSource, NwgError>

Try to read an image from a file path. The file type can be any of the native WIC codecs (https://docs.microsoft.com/en-us/windows/win32/wic/native-wic-codecs)

  • If there is an error during the decoding, returns a NwgError.
  • If the image decoder was not initialized, this method panics

This method returns a ImageSource object

Source

pub fn from_stream(&self, stream: &[u8]) -> Result<ImageSource, NwgError>

Build an image from a stream of data. The file type can be any of the native WIC codecs (https://docs.microsoft.com/en-us/windows/win32/wic/native-wic-codecs)

  • If there is an error during the decoding, returns a NwgError.
  • If the image decoder was not initialized, this method panics

This method copies the bytes and returns a ImageSource object

Source

pub fn resize_image( &self, image: &ImageData, new_size: [u32; 2], ) -> Result<ImageData, NwgError>

Resize an image, returning the new resized image. The pixel format might change.

Trait Implementations§

Source§

impl Default for ImageDecoder

Source§

fn default() -> ImageDecoder

Returns the “default value” for a type. Read more
Source§

impl Drop for ImageDecoder

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.