Set application icon #1281
-
I am now trying to set an application icon to my iced application. I've tried this as follows:
However, in that case,
I've also tried this with icons of different sizes and file types, and sometimes it returns an error like the following instead (for a 32x32 .ico):
I haven't been able to find a way to get this to work. Can someone please help me with that? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
You need to decode the image data into raw bytes first. Here's an example which uses the static ICON: &[u8] = include_bytes!("../icon.png");
const ICON_HEIGHT: u32 = 64;
const ICON_WIDTH: u32 = 64;
fn main() {
let image = image::load_from_memory(ICON).unwrap();
let icon = iced::window::Icon::from_rgba(image.as_bytes().to_vec(), ICON_HEIGHT, ICON_WIDTH).unwrap();
let settings = iced::settings::Settings {
window: iced::window::Settings {
icon: Some(icon),
..Default::default()
},
..Default::default()
};
YourApplication::run(settings)
...
} |
Beta Was this translation helpful? Give feedback.
-
i am using iced 0.4.2 on windows 10 with the accepted answer code, but still get the |
Beta Was this translation helpful? Give feedback.
You need to decode the image data into raw bytes first.
Here's an example which uses the
image
crate to do that. Replace the constants with the properties/location/etc of your actual icon.