-
Notifications
You must be signed in to change notification settings - Fork 95
/
png.rs
30 lines (27 loc) · 1 KB
/
png.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// TODO: Remove all the wasm32 cfg guards once this compiles with piet-web
#[cfg(not(target_arch = "wasm32"))]
use piet::kurbo::Line;
#[cfg(not(target_arch = "wasm32"))]
use piet::{Color, RenderContext};
#[cfg(not(target_arch = "wasm32"))]
use piet_common::Device;
/// Feature "png" needed for save_to_file() and it's disabled by default for optional dependencies
/// cargo run --example png --features png
fn main() {
#[cfg(not(target_arch = "wasm32"))]
{
let mut device = Device::new().unwrap();
let width = 640;
let height = 480;
let mut bitmap = device.bitmap_target(width, height, 1.0).unwrap();
let mut rc = bitmap.render_context();
rc.clear(Color::WHITE);
let brush = rc.solid_brush(Color::rgb8(0x00, 0x00, 0x80));
rc.stroke(Line::new((10.0, 10.0), (100.0, 50.0)), &brush, 1.0);
rc.finish().unwrap();
std::mem::drop(rc);
bitmap
.save_to_file("temp-image.png")
.expect("file save error");
}
}