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: PathBufThe 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: i32The width in pixels of the image.
height: i32The height in pixels of the image.
transparent_colour: Option<Color>A color that should be interpreted as transparent (0 alpha), if any.
Trait Implementations§
impl Eq for Image
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> 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
Mutably borrows from an owned value. Read more