Giter Club home page Giter Club logo

rust-bmp's Introduction

rust-bmp

Build Status

Full documentation

Small module for reading and writing bitmap images. See the documentation for the current status of BMP encoding and decoding support.

Usage

An updated version of the library should be available on crates.io. Add the following to your Cargo.toml to get is a dependency.

[dependencies]
bmp = "*"

###Initializing Initialize a new image with the new function, by specifying width and height.

extern crate bmp;
use bmp::Image;

let mut img = Image::new(100, 100);

###Editing Edit image data using the get_pixel and set_pixel functions. Save an image with the save function, by specifying the path. The function returns an IoResult which indicates whether the save was successful or not.

let pixel = img.get_pixel(0, 0);
img.set_pixel(50, 50, Pixel { r: 255, g: 255, b: 255 });
let _ = img.save("path/to/img.bmp");

###Opening Open an existing image with the open function, by specifying the path. The function returns a BmpResult, that contains either a Image or a BmpError.

extern crate bmp;

let img = bmp::open("path/to/img.bmp").unwrap_or_else(|e| {
    panic!("Failed to open: {}", e);
});

Coordinate convention

The BMP images are accessed in row-major order, where point (0, 0) is defined to be in the upper left corner of the image. Example

#[macro_use]
extern crate bmp;
use bmp::{Image, Pixel};

fn main() {
    let mut img = Image::new(256, 256);

    for (x, y) in img.coordinates() {
        img.set_pixel(x, y, px!(x, y, 200));
    }
    let _ = img.save("img.bmp");
}

rust-bmp's People

Contributors

posixphreak avatar okey avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.