Expand description
Generate distance field bitmaps for rendering as pseudo-vector images in shaders.
An example usecase for the library would be to automatically convert asset images. You can achieve this by having a build.rs
similar to this:
use std::fs::File;
use distance_field::DistanceFieldExt;
fn convert_image_to_dfield(input: &str, output: &str) {
// Load the 'input' image
let img = image::open(input).unwrap();
// Generate a distance field from the image
let outbuf = img.grayscale().distance_field(distance_field::Options {
size: (128, 128),
max_distance: 256,
..Default::default()
});
// Save it to 'output' as a PNG
image::DynamicImage::ImageLuma8(outbuf).save(output).unwrap();
}
fn main() {
convert_image_to_dfield("img/input.png", "output.png");
}
Structs§
- Options
- The options passed as the argument to the
distance_field
method.
Traits§
- Distance
Field Ext - A trait adding the
distance_field
function to image types.