pub struct BitMap { /* private fields */ }
Expand description
In memory representation of a bitmap allowing for easier editing
Implementations§
Source§impl BitMap
This block deals with constructors, and getters and setters
impl BitMap
This block deals with constructors, and getters and setters
Sourcepub fn read(filename: &str) -> Result<BitMap, String>
pub fn read(filename: &str) -> Result<BitMap, String>
Create a bitmap by reading in a .bmp file
Fails if filename doesn’t end with “.bmp”
Sourcepub fn new(width: u32, height: u32) -> BitMap
pub fn new(width: u32, height: u32) -> BitMap
Create a new bitmap image in memory
Fill all the pixels as white
Sourcepub fn create(
width: u32,
height: u32,
pixels: Vec<Rgba>,
) -> Result<BitMap, &'static str>
pub fn create( width: u32, height: u32, pixels: Vec<Rgba>, ) -> Result<BitMap, &'static str>
Create a new image from a list of pixels
Sourcepub fn get_pixel(&self, x: u32, y: u32) -> Option<&Rgba>
pub fn get_pixel(&self, x: u32, y: u32) -> Option<&Rgba>
Get a pixel at a specific x and y coordinate
Sourcepub fn get_pixels(&self) -> &Vec<Rgba>
pub fn get_pixels(&self) -> &Vec<Rgba>
Get a reference to the collection of all the pixels inside of the image
Sourcepub fn get_height(&self) -> u32
pub fn get_height(&self) -> u32
Get the height of the image
Sourcepub fn get_estimated_file_size_in_bytes(&self) -> u32
pub fn get_estimated_file_size_in_bytes(&self) -> u32
Get the estimated file size in bytes
Sourcepub fn get_filename(&self) -> Option<&String>
pub fn get_filename(&self) -> Option<&String>
Get a reference to the file name of the bitmap if it exists
Sourcepub fn get_all_unique_colors(&self) -> Vec<Rgba>
pub fn get_all_unique_colors(&self) -> Vec<Rgba>
Get all the unique colors from pixels, remove any duplicates
Sourcepub fn is_image_transparent(&self) -> bool
pub fn is_image_transparent(&self) -> bool
Check if there is at least one pixel that it translucent
Source§impl BitMap
This block deals with saving the image
impl BitMap
This block deals with saving the image
Sourcepub fn save(&self) -> Result<(), String>
pub fn save(&self) -> Result<(), String>
Save the image to its original location
Fail if no original location is linked to the current bitmap
Sourcepub fn save_as(&self, filename: &str) -> Result<(), String>
pub fn save_as(&self, filename: &str) -> Result<(), String>
Save the image to a new location on disk
Sourcepub fn simplify_and_save(&self) -> Result<(), String>
pub fn simplify_and_save(&self) -> Result<(), String>
Analyze the currently recorded pixels and try and find the lowest bit count possible to save the images at.
The bit depth will be: if there are at most 2 colors present, 2 bit if there are at most 16 colors present, 4 bit if there are at most 256 colors present, 8 bit if there are more then 256 colors and all alphas are 100, 24 bit if there are more then 256 colors and at least one alpha is not 100, 32 bit
Sourcepub fn simplify_and_save_as(&self, filename: &str) -> Result<(), String>
pub fn simplify_and_save_as(&self, filename: &str) -> Result<(), String>
Analyze the currently recorded pixels and try and find the lowest bit count possible to save the images at.
The bit depth will be: if there are at most 2 colors present, 2 bit if there are at most 16 colors present, 4 bit if there are at most 256 colors present, 8 bit if there are more then 256 colors and all alphas are 100, 24 bit if there are more then 256 colors and at least one alpha is not 100, 32 bit
Source§impl BitMap
This block deals with creating a new bitmap from an existing one and manipulating
bit maps using other bitmaps
impl BitMap
This block deals with creating a new bitmap from an existing one and manipulating bit maps using other bitmaps
Sourcepub fn crop(
&self,
from_x: u32,
from_y: u32,
to_x: u32,
to_y: u32,
) -> Result<BitMap, &'static str>
pub fn crop( &self, from_x: u32, from_y: u32, to_x: u32, to_y: u32, ) -> Result<BitMap, &'static str>
Crop a given area of the current image
@param {u32} starting x position @param {u32} starting y position @param {u32} ending x position @param {u32} ending y position
@exception {&’static str} error message if the starting x and ending x or starting y and ending y is out of the image with height or width, throw an error
Source§impl BitMap
This block deals with coloring the image
impl BitMap
This block deals with coloring the image
Sourcepub fn set_pixel(
&mut self,
x: u32,
y: u32,
color: Rgba,
) -> Result<(), &'static str>
pub fn set_pixel( &mut self, x: u32, y: u32, color: Rgba, ) -> Result<(), &'static str>
Set the color of a pixel
@param {u32} x position @param {u32} y position @param {Rgba} color to set pixel
Sourcepub fn color_to_gray(&mut self)
pub fn color_to_gray(&mut self)
Convert image from a colored image to gray
Sourcepub fn replace_all_color(&mut self, from: Rgba, to: Rgba)
pub fn replace_all_color(&mut self, from: Rgba, to: Rgba)
Find all the pixels that are the same as the from color and convert them all to the “to” color.
@param {Rgba} from color @param {Rgba} to color
Sourcepub fn fill_region(
&mut self,
x: u32,
y: u32,
color: Rgba,
) -> Result<(), &'static str>
pub fn fill_region( &mut self, x: u32, y: u32, color: Rgba, ) -> Result<(), &'static str>
Fill a region of an image with a color. The only colors that get changed are those that are the same as the pixel found at the given x and y value
@param {u32} x position @param {u32} y position @param {Rgba} color to use to replace the other color
Source§impl BitMap
This block is only meant for resizing images using one of the 3 (so far only
2 implemented) algorithms (nearest neighbor, bilinear, bicubic) as well as
rotating the image left or right by 90 degrees
impl BitMap
This block is only meant for resizing images using one of the 3 (so far only 2 implemented) algorithms (nearest neighbor, bilinear, bicubic) as well as rotating the image left or right by 90 degrees
Sourcepub fn fast_resize_by(&mut self, factor: f32) -> Result<(), &'static str>
pub fn fast_resize_by(&mut self, factor: f32) -> Result<(), &'static str>
Resize the current image by using nearest neighbor algorithm. Scale image to image size * the factor
Sourcepub fn fast_resize_to(&mut self, width: u32, height: u32)
pub fn fast_resize_to(&mut self, width: u32, height: u32)
Resize the current image by using nearest neighbor algorithm. Scale image to specified width and height
Sourcepub fn resize_by(&mut self, factor: f32) -> Result<(), &'static str>
pub fn resize_by(&mut self, factor: f32) -> Result<(), &'static str>
Resize the current image by using bilinear interpolation algorithm. Scale image to image size * the factor
Sourcepub fn resize_to(&mut self, width: u32, height: u32)
pub fn resize_to(&mut self, width: u32, height: u32)
Resize the current image by using bilinear interpolation algorithm. Scale image to specified width and height
Sourcepub fn slow_resize_by(&mut self, factor: f32) -> Result<(), &'static str>
pub fn slow_resize_by(&mut self, factor: f32) -> Result<(), &'static str>
Resize the current image by using bicubic interpolation algorithm. Scale image to image size * the factor
Sourcepub fn slow_resize_to(&mut self, width: u32, height: u32)
pub fn slow_resize_to(&mut self, width: u32, height: u32)
Resize the current image by using bicubic interpolation algorithm. Scale image to specified width and height
Sourcepub fn slow_resize(&mut self, width: u32, height: u32)
pub fn slow_resize(&mut self, width: u32, height: u32)
Resize the current image by using bicubic interpolation algorithm
Sourcepub fn rotate_right(&mut self)
pub fn rotate_right(&mut self)
Rotate the entire image right by 90 degrees
Sourcepub fn rotate_left(&mut self)
pub fn rotate_left(&mut self)
Rotate the entire image left by 90 degrees