pub struct Image { /* private fields */ }
Expand description
An easy way to load PNG images and blit them on the console
Implementations
sourceimpl Image
impl Image
sourcepub fn new(file_path: &str) -> Self
pub fn new(file_path: &str) -> Self
Create an image and load a PNG file. On the web platform, image loading is asynchronous. Using blit methods before the image is loaded has no impact on the console.
sourcepub fn width(&self) -> u32
pub fn width(&self) -> u32
Returns the image’s width in pixels or 0 if the image has not yet been loaded
sourcepub fn height(&self) -> u32
pub fn height(&self) -> u32
Returns the image’s height in pixels or 0 if the image has not yet been loaded
sourcepub fn pixel(&self, x: u32, y: u32) -> Option<Color>
pub fn pixel(&self, x: u32, y: u32) -> Option<Color>
get the color of a specific pixel inside the image
sourcepub fn put_pixel(&mut self, x: u32, y: u32, color: Color)
pub fn put_pixel(&mut self, x: u32, y: u32, color: Color)
sets the color of a specific pixel inside the image
sourcepub fn try_load(&mut self) -> bool
pub fn try_load(&mut self) -> bool
Check if the image has been loaded.
Since there’s no background thread doing the work for you, you have to call some method on image for it to actually load.
Use either Image::try_load
, [Image::get_size
], Image::blit
or Image::blit_ex
to run the loading code.
sourcepub fn try_get_size(&mut self) -> Option<(u32, u32)>
pub fn try_get_size(&mut self) -> Option<(u32, u32)>
If the image has already been loaded, return its size, else return None
sourcepub fn blit(
&mut self,
con: &mut Console,
x: i32,
y: i32,
transparent: Option<Color>
)
pub fn blit(
&mut self,
con: &mut Console,
x: i32,
y: i32,
transparent: Option<Color>
)
blit an image on a console
x,y are the coordinate of the top left image pixel in the console
image pixels using the transparent color will be ignored
sourcepub fn blit_ex(
&mut self,
con: &mut Console,
x: f32,
y: f32,
scalex: f32,
scaley: f32,
angle: f32,
transparent: Option<Color>
)
pub fn blit_ex(
&mut self,
con: &mut Console,
x: f32,
y: f32,
scalex: f32,
scaley: f32,
angle: f32,
transparent: Option<Color>
)
blit an image on a console
x,y are the coordinate of the image center in the console image can be scaled and rotated (angle is in radians) image pixels using the transparent color will be ignored
sourcepub fn blit_2x(
&mut self,
con: &mut Console,
dx: i32,
dy: i32,
sx: i32,
sy: i32,
w: Option<i32>,
h: Option<i32>,
transparent: Option<Color>
)
pub fn blit_2x(
&mut self,
con: &mut Console,
dx: i32,
dy: i32,
sx: i32,
sy: i32,
w: Option<i32>,
h: Option<i32>,
transparent: Option<Color>
)
blit an image on the console, using the subcell characters to achieve twice the normal resolution. This uses the CHAR_SUBCELL_* ascii codes (from 226 to 232):
Comparison before/after subcell in the chronicles of Doryen :
Pyromancer! screenshot, making full usage of subcell resolution: