Image

Struct Image 

Source
pub struct Image {
    pub source: PathBuf,
    pub width: i32,
    pub height: i32,
    pub transparent_colour: Option<Color>,
}
Expand description

A reference to an image stored somewhere within the filesystem.

Fields§

§source: PathBuf

The uncanonicalized filepath of the image, starting from the path given to load the file this image is in. See the example for more details.

§Note

The crate does not currently support embedded images (Even though Tiled does not allow creating maps with embedded image data, the TMX format does; source)

§Example

use std::path::Path;
use std::fs::File;
use tiled::*;

let map = Loader::new().load_tmx_map("assets/folder/tiled_relative_paths.tmx")?;

let image_layer = match map
    .layers()
    .find(|layer| layer.name == "image")
    .unwrap()
    .layer_type()
{
    LayerType::Image(layer) => layer,
    _ => panic!(),
};

// Image layer has an image with the source attribute set to "../tilesheet.png"
// Given the information we gave to the `parse_file` function, the image source should be
// "assets/folder/../tilesheet.png". The filepath is not canonicalized.
let image_source = &image_layer.image.as_ref().unwrap().source;

assert_eq!(
    image_source,
    Path::new("assets/folder/../tilesheet.png")
);

// Figuring out the real path of the image is as easy as canonicalizing it.
let image_source = image_source.canonicalize()?;
assert!(File::open(image_source).is_ok());

Check the assets/tiled_relative_paths.tmx file at the crate root to see the structure of the file this example is referring to.

§width: i32

The width in pixels of the image.

§height: i32

The height in pixels of the image.

§transparent_colour: Option<Color>

A color that should be interpreted as transparent (0 alpha), if any.

Trait Implementations§

Source§

impl Clone for Image

Source§

fn clone(&self) -> Image

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Image

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Image

Source§

fn eq(&self, other: &Image) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Image

Source§

impl StructuralPartialEq for Image

Auto Trait Implementations§

§

impl Freeze for Image

§

impl RefUnwindSafe for Image

§

impl Send for Image

§

impl Sync for Image

§

impl Unpin for Image

§

impl UnwindSafe for Image

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.