#image #bmp #editing

bmp-rust

Rust library to read, write, and create BMP Image files

7 releases

Uses new Rust 2021

new 0.2.5 Dec 1, 2022
0.2.4 Nov 21, 2022
0.1.2 Oct 30, 2022

#101 in Images

Download history 25/week @ 2022-10-15 3/week @ 2022-10-22 53/week @ 2022-10-29 3/week @ 2022-11-05 3/week @ 2022-11-12 140/week @ 2022-11-19 38/week @ 2022-11-26

194 downloads per month

MIT license

73KB
1K SLoC

BMP Rust

BMP Rust is a rust library to read and write .bmp Image files. It has zero dependencies.

Install

Obviously, install Rust. Add bmp-rust to your Cargo.toml file

[dependencies]
bmp-rust ="0.2.4"

You can now use the crate:

use bmp_rust::bmp::BMP;

Documentation

First, load a BMP file by file path, or create a new one:

let mut bmp_from_file = BMP::new_from_file("midnight.bmp");
let mut bmp_from_scratch = BMP::new(15, 15, None);

Information can now be read from the file:

let file_size = bmp_from_file.get_size(true);
let dib_header = bmp_from_file.get_dib_header().unwrap();
let width = dib_header.width;
let height = dib_header.height;
let pixel_color = bmp_from_file.get_color_of_px(10, 10).unwrap();

Or new pixel data can be written to it:

bmp_from_file.change_color_of_pixel(10, 10, [233, 71, 255, 255]).expect("Failed to change color of pixel");
bmp_from_file.fill_bucket([155, 42, 66, 255], 35, 40).expect("Failed to bucket fill");
bmp_from_file.draw_line([100, 65, 45, 255], [20, 20], [52, 52]).expect("Failed to draw line");
bmp_from_file.draw_rectangle(None, Some([255, 255, 255, 255]), [0,2], [15,11]).expect("Failed to draw rect");
bmp_from_file.draw_ellipse([23, 25], 10, 12, [255, 0, 0, 255], Some([125, 64, 64, 255]), true).expect("Failed to draw ellipse");
bmp_from_file.invert(None).expect("Failed to invert");
bmp_from_file.change_opacity(25).expect("Failed to change opacity");
bmp_from_file.draw_image(5, 5, bmp_from_scratch).expect("Failed to draw image");
bmp_from_file.translate(-3, 5);

Look at the source code or tests/example for more functions, and their usage.

docs.rs

No runtime deps