Skip to content

Instantly share code, notes, and snippets.

@chrsan
Created June 7, 2020 13:54
Show Gist options
  • Save chrsan/2cec6255c2376d94ee73fd680ef102e8 to your computer and use it in GitHub Desktop.
Save chrsan/2cec6255c2376d94ee73fd680ef102e8 to your computer and use it in GitHub Desktop.
cairo-rs stride fix
[package]
name = "cairo-rs-stride-fix"
version = "0.1.0"
authors = ["Christer Sandberg <christer.sandberg@svt.se>"]
edition = "2018"
[dependencies]
cairo-sys-rs = "0.9.1"
[dependencies.cairo-rs]
version = "0.8.1"
features = ["png"]
default-features = false
fn main() {
let mut pixels: Vec<u8> = vec![0; 4 * 1920 * 1080];
let surface = unsafe {
let ptr = cairo_sys::cairo_image_surface_create_for_data(
pixels.as_mut_ptr(),
cairo_sys::FORMAT_A_RGB32,
1280,
720,
4 * 1920,
);
cairo::ImageSurface::from_raw_full(ptr).unwrap()
};
let cr = cairo::Context::new(&surface);
cr.set_antialias(cairo::Antialias::Best);
cr.set_source_rgba(1.0, 0.0, 0.0, 1.0);
cr.rectangle(100.0, 100.0, 640.0, 360.0);
cr.fill();
let mut file = std::fs::File::create("sample.png").unwrap();
surface.write_to_png(&mut file).unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment