Skip to content

Instantly share code, notes, and snippets.

@richardanaya
Created July 31, 2020 16:00
Show Gist options
  • Select an option

  • Save richardanaya/46d8ec5b4111ce2f5548ef7e5060b87b to your computer and use it in GitHub Desktop.

Select an option

Save richardanaya/46d8ec5b4111ce2f5548ef7e5060b87b to your computer and use it in GitHub Desktop.
pub fn image_from_resource(path:&str) -> ImageSurface{
let pb = Pixbuf::from_resource(path).unwrap();
let mut pixels = unsafe { pb.get_pixels().to_owned() };
let pslice = pixels.as_mut_slice();
ImageSurface::create_for_data(pslice,if pb.get_has_alpha() { Format::ARgb32 } else { Format::Rgb24 },pb.get_width(),pb.get_height(),pb.get_width()).unwrap()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment