pub struct Image { /* private fields */ }
Expand description
A simple image loaded from NvDialog. This is the equivalent to NvdImage
, although the implementation
makes a few extra safety checks from the Rust side.
Implementations§
Source§impl Image
impl Image
Sourcepub fn from_filename(filename: PathBuf) -> Result<Self, ImageError>
pub fn from_filename(filename: PathBuf) -> Result<Self, ImageError>
Creates an Image
from a specified filename.
This function attempts to load an image from the given file path using NvDialog’s image loading facilities. It performs a few checks to ensure robustness and safety from the Rust side.
§Arguments
filename
- APathBuf
specifying the file path of the image to be loaded.
§Returns
Result<Self, ImageError>
- Returns anOk
variant containing theImage
if successful, or anImageError
if an error occurs during the process.
§Errors
ImageError::PathNotFound
- Returned if the file path does not exist.ImageError::UnknownError
- Returned if the image cannot be created from the data.
§Safety
This function makes use of unsafe
blocks to interface with the C functions
from NvDialog. It is assumed that nvd_image_from_filename
and
nvd_create_image
are safe to call with the provided arguments.
Sourcepub unsafe fn from_data(
data: &[u8],
width: u32,
height: u32,
) -> Result<Self, ImageError>
pub unsafe fn from_data( data: &[u8], width: u32, height: u32, ) -> Result<Self, ImageError>
Creates an Image
from the raw data of an image file.
This function creates an Image
from raw data that is assumed to be in a format
that NvDialog can read. The data is sent to the NvDialog library without any
checking on the Rust side, so it is left up to the user to ensure that the data
is valid.
§Safety
This function is marked unsafe
because the data passed to it is not checked
in any way. If the data is not valid, it may cause undefined behavior when
passed to the C library.
§Arguments
data
- The raw image data. This is assumed to be the contents of an image file and should be in a format that NvDialog can read.width
- The width of the image in pixels.height
- The height of the image in pixels.
§Returns
Result<Self, ImageError>
- Returns anOk
variant containing theImage
if successful, or anImageError
if an error occurs.
§Errors
ImageError::InvalidFormat
- Returned if the data is not in a valid format for NvDialog.ImageError::UnknownError
- Returned if the image cannot be created from the data for some other reason.