Skip to content

Set application icon #1281

Answered by BlackHoleFox
KiraResari asked this question in Q&A
Mar 11, 2022 · 2 comments · 6 replies
Discussion options

You must be logged in to vote

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.

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::

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
6 replies
@BlackHoleFox
Comment options

@KiraResari
Comment options

@BlackHoleFox
Comment options

@KiraResari
Comment options

@BlackHoleFox
Comment options

Answer selected by KiraResari
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants