[−][src]Struct raster::Image 
A struct for easily representing a raster image.
Fields
width: i32
                           Width of image in pixels.
height: i32
                           Height of image in pixels.
bytes: Vec<u8>
                           Vector containing sequence of bytes in RGBA format.
Methods
impl<'a> Image[src] 
impl<'a> Imagepub fn blank(w: i32, h: i32) -> Image[src] 
pub fn blank(w: i32, h: i32) -> ImageCreate a blank image. Default color is black.
Examples
use raster::Image; let image = Image::blank(2, 2); println!("{:?}", image.bytes); assert_eq!(image.width, 2); assert_eq!(image.height, 2);
pub fn check_pixel(&self, x: i32, y: i32) -> bool[src] 
pub fn check_pixel(&self, x: i32, y: i32) -> boolCheck if there is a pixel at this location given by x and y.
Examples
use raster::Image; let image = Image::blank(2, 2); assert_eq!(image.check_pixel(0, 0), true); assert_eq!(image.check_pixel(3, 3), false);
pub fn histogram(&self) -> RasterResult<Histogram>[src] 
pub fn histogram(&self) -> RasterResult<Histogram>Get the histogram of the image.
Examples
Visualizing the histogram of the red channel of this image:
Image:

Code:
use raster::Image; use raster::Color; let image = raster::open("tests/in/sample.png").unwrap(); let (r_bin, _, _, _) = image.histogram().unwrap(); let mut max_r_bin = 0; for (_, count) in &r_bin { if *count > max_r_bin { max_r_bin = *count; } } let canvas_w = 256; let canvas_h: i32 = 100; let mut image = Image::blank(canvas_w, canvas_h); raster::editor::fill(&mut image, Color::rgb(214, 214, 214)).unwrap(); for x in 0..256 as i32 { // 0-255 let key = x as u8; match r_bin.get(&key) { Some(count) => { let height = (canvas_h as f32 * (*count as f32 / max_r_bin as f32)).round() as i32; for y in canvas_h-height..canvas_h { image.set_pixel(x, y, &Color::hex("#e22d11").unwrap()).unwrap(); } }, None => {} } } raster::save(&image, "tests/out/histogram.png").unwrap();
Histogram:

Photoshop's result:

pub fn get_pixel(&self, x: i32, y: i32) -> RasterResult<Color>[src] 
pub fn get_pixel(&self, x: i32, y: i32) -> RasterResult<Color>Get pixel in a given x and y location of an image.
Errors
If either the x or y coordinate falls out of bounds, this will fail with
RasterError::PixelOutOfBounds.
Examples
use raster::Image; use raster::Color; let mut image = Image::blank(2, 2); // Creates a 2x2 black image. let pixel = image.get_pixel(0, 0).unwrap(); assert_eq!(0, pixel.r); assert_eq!(0, pixel.g); assert_eq!(0, pixel.b); assert_eq!(255, pixel.a);
pub fn set_pixel(&mut self, x: i32, y: i32, color: &Color) -> RasterResult<()>[src] 
pub fn set_pixel(&mut self, x: i32, y: i32, color: &Color) -> RasterResult<()>Set pixel in a given x and y location of an image.
Errors
If either the x or y coordinate falls out of bounds, this will fail with
RasterError::PixelOutOfBounds.
If the calculated byte start index is less than 0, this will fail with
RasterError::InvalidStartIndex.
Examples
use raster::Image; use raster::Color; let mut image = Image::blank(2, 2); // Creates a 2x2 black image. let _ = image.set_pixel(0, 0, &Color::rgba(255, 0, 0, 255)); // Set first pixel to red let pixel = image.get_pixel(0, 0).unwrap(); assert_eq!(255, pixel.r); assert_eq!(0, pixel.g); assert_eq!(0, pixel.b); assert_eq!(255, pixel.a);
Trait Implementations
impl Clone for Image[src] 
impl Clone for Imagefn clone(&self) -> Image[src] 
fn clone(&self) -> ImageReturns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0[src] 
fn clone_from(&mut self, source: &Self)Performs copy-assignment from source. Read more
impl Debug for Image[src] 
impl Debug for ImageAuto Trait Implementations
Blanket Implementations
impl<T> From for T[src] 
impl<T> From for Timpl<T, U> Into for T where
    U: From<T>, [src] 
impl<T, U> Into for T where
    U: From<T>, impl<T> ToOwned for T where
    T: Clone, [src] 
impl<T> ToOwned for T where
    T: Clone, type Owned = T
fn to_owned(&self) -> T[src] 
fn to_owned(&self) -> TCreates owned data from borrowed data, usually by cloning. Read more
fn clone_into(&self, target: &mut T)[src] 
fn clone_into(&self, target: &mut T)🔬 This is a nightly-only experimental API.  (toowned_clone_into)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<T, U> TryFrom for T where
    T: From<U>, [src] 
impl<T, U> TryFrom for T where
    T: From<U>, type Error = !
try_from)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src] 
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>try_from)Performs the conversion.
impl<T> Borrow for T where
    T: ?Sized, [src] 
impl<T> Borrow for T where
    T: ?Sized, impl<T> BorrowMut for T where
    T: ?Sized, [src] 
impl<T> BorrowMut for T where
    T: ?Sized, fn borrow_mut(&mut self) -> &mut T[src] 
fn borrow_mut(&mut self) -> &mut TMutably borrows from an owned value. Read more
impl<T, U> TryInto for T where
    U: TryFrom<T>, [src] 
impl<T, U> TryInto for T where
    U: TryFrom<T>, type Error = <U as TryFrom<T>>::Error
try_from)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src] 
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>try_from)Performs the conversion.
impl<T> Any for T where
    T: 'static + ?Sized, [src] 
impl<T> Any for T where
    T: 'static + ?Sized, fn get_type_id(&self) -> TypeId[src] 
fn get_type_id(&self) -> TypeId🔬 This is a nightly-only experimental API.  (get_type_id)
this method will likely be replaced by an associated static
Gets the TypeId of self. Read more
impl<T> SetParameter for T[src] 
impl<T> SetParameter for T