1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#[allow(dead_code)]
pub fn save_image<'a>(
    context: impl Into<Option<&'a mut skia_safe::gpu::DirectContext>>,
    image: &skia_safe::Image,
    name: &str,
) {
    use std::fs::File;
    use std::io::Write;

    let data = image
        .encode(context.into(), skia_safe::EncodedImageFormat::PNG, None)
        .unwrap();
    let bytes = data.as_bytes();
    let filename = format!("{}.png", name);
    let mut file = File::create(filename).unwrap();
    file.write_all(bytes).unwrap();
}