pub fn from_bytes(bytes: &[u8], format: ImageFormat) -> Result<Self> {
        let buf_reader = BufReader::new(Cursor::new(bytes));
        let img = match format {
            ImageFormat::Png => {
                ::image::DynamicImage::from_decoder(::image::png::PngDecoder::new(buf_reader)?)?
            }
            ImageFormat::Bmp => {
                ::image::DynamicImage::from_decoder(::image::bmp::BmpDecoder::new(buf_reader)?)?
            }
            ImageFormat::Jpeg => {
                ::image::DynamicImage::from_decoder(::image::jpeg::JpegDecoder::new(buf_reader)?)?
            }
        };
        Ok(Image {
            img: img.into_rgba(),
        })
    }
/// Load an image from a byte slice in the specified format.
///
/// # Example
///
/// ```
/// # use riddle_image::*; fn main() -> Result<(), ImageError> {
/// let png_bytes = include_bytes!("../../example_assets/image.png");
/// let png_img = Image::from_bytes(&png_bytes[..], ImageFormat::Png)?;
/// # Ok(()) }
/// ```
Load an image from a byte slice in the specified format.
Load an image from a byte slice in the specified format .
pub fn from_bytes(bytes: &[u8], format: ImageFormat) -> Result<Self> {
        let buf_reader = BufReader::new(Cursor::new(bytes));
        let img = match format {
            ImageFormat::Png => {
                ::image::DynamicImage::from_decoder(::image::png::PngDecoder::new(buf_reader)?)?
            }
            ImageFormat::Bmp => {
                ::image::DynamicImage::from_decoder(::image::bmp::BmpDecoder::new(buf_reader)?)?
            }
            ImageFormat::Jpeg => {
                ::image::DynamicImage::from_decoder(::image::jpeg::JpegDecoder::new(buf_reader)?)?
            }
        };
        Ok(Image {
            img: img.into_rgba(),
        })
    }
pub fn from_bytes ( bytes : & [ u8 ] , format : ImageFormat ) -> Result < Self > { let buf_reader = BufReader :: new ( Cursor :: new ( bytes ) ) ; let img = match format { ImageFormat :: Png => { :: image :: DynamicImage :: from_decoder ( :: image :: png :: PngDecoder :: new ( buf_reader ) ? ) ? } ImageFormat :: Bmp => { :: image :: DynamicImage :: from_decoder ( :: image :: bmp :: BmpDecoder :: new ( buf_reader ) ? ) ? } ImageFormat :: Jpeg => { :: image :: DynamicImage :: from_decoder ( :: image :: jpeg :: JpegDecoder :: new ( buf_reader ) ? ) ? } } ; Ok ( Image { img : img . into_rgba ( ) , } ) }
Load an image from a byte slice in the specified format.
Load an image from a byte slice in the specified format .
bytes
&[u8]
format
ImageFormat
bytes
&[u8]
format
ImageFormat
example
None
use riddle_image::*; fn main() -> result<(), imageerror> {
let png_bytes = include_bytes!("../../example_assets/image.png");
let png_img = Image::from_bytes(&png_bytes[..], ImageFormat::Png)?.
let png_bytes = include_bytes! ( " .. / .. / example_assets / image . png " ) ; let png_img = Image :: from_bytes ( &png_bytes [ .. ] ImageFormat :: Png ) ? .
ok(()) }
None