examples/window_icon.rs: De-duplicate code (#988)

This commit is contained in:
Felix Rabe 2019-06-27 17:59:13 +02:00 committed by Osspial
parent ac08601b40
commit dd38fab2f3

View file

@ -13,17 +13,7 @@ fn main() {
// you'll be bitten by the low-quality downscaling built into the WM.
let path = concat!(env!("CARGO_MANIFEST_DIR"), "/examples/icon.png");
let (icon_rgba, icon_width, icon_height) = {
let image = image::open(path).expect("Failed to open icon path");
use image::{GenericImageView, Pixel};
let (width, height) = image.dimensions();
let mut rgba = Vec::with_capacity((width * height) as usize * 4);
for (_, _, pixel) in image.pixels() {
rgba.extend_from_slice(&pixel.to_rgba().data);
}
(rgba, width, height)
};
let icon = Icon::from_rgba(icon_rgba, icon_width, icon_height).expect("Failed to open icon");
let icon = load_icon(Path::new(path));
let event_loop = EventLoop::new();