-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SVG images are blurry when ctx.pixel_per_point
is not equal to 1.0
#3453
Comments
Still got this in the latest version. |
Switching to let base = 24.0;
let multiplier = 12.0;
let true_size = base * multiplier;
let size = Vec2 {
x: true_size / ctx.pixels_per_point(),
y: true_size / ctx.pixels_per_point(),
};
let img_src = include_image!("images/folder_open.svg");
ui.add(ImageButton::new(
Image::new(img_src)
.max_size(size)
.maintain_aspect_ratio(true)
.texture_options(TextureOptions::NEAREST)
.rounding(4.0),
)); |
We need to take egui/crates/egui_extras/src/loaders/svg_loader.rs Lines 53 to 55 in 8bf498d
egui/crates/egui_extras/src/image.rs Lines 226 to 237 in 8bf498d
Should be an easy fix for anyone who is interested! |
New API:
![grafik](https://cdn.statically.io/img/private-user-images.githubusercontent.com/341098/274127618-89ff6b18-a320-4076-819c-f854d44df9fb.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE0MzE2MTMsIm5iZiI6MTcyMTQzMTMxMywicGF0aCI6Ii8zNDEwOTgvMjc0MTI3NjE4LTg5ZmY2YjE4LWEzMjAtNDA3Ni04MTljLWY4NTRkNDRkZjlmYi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzE5JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcxOVQyMzIxNTNaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0yNDEyOTdlNDkxZTFkOTE1ZTM3Y2Q5ZjE0NmE4ZDhhZjM3ODlkN2U5ZDI4YWMzMjJmMGEzNGU3M2VhNDQ0YmQ2JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.nhlDEfwvXWA8tK4Ylv0EU1Q8niEwCptJTYA3FFJE9v8)
Old API :
![grafik](https://cdn.statically.io/img/private-user-images.githubusercontent.com/341098/274127998-f49d06fe-e0a5-49f0-9ff4-5c95b9d78e1f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE0MzE2MTMsIm5iZiI6MTcyMTQzMTMxMywicGF0aCI6Ii8zNDEwOTgvMjc0MTI3OTk4LWY0OWQwNmZlLWUwYTUtNDlmMC05ZmY0LTVjOTViOWQ3OGUxZi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzE5JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcxOVQyMzIxNTNaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1mMzZjYjZkMDAyODcxMTUxYWI3YzgzMDM4ZGRlYWIzZGUwYTZiZjU2YmQ4ZWY3Yjc3YWE0Mzg3NzFmNzczYTdlJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.JnXA1JKKkGuUYdtQuLR4HRM5GAOVgDf07mbtetmGErI)
It's a 4k issue - somewhere internal, the pixels per point don't get valued.
My usage is:
ui.add(ImageButton::new(icon.clone().fit_to_exact_size(size_points).tint(tint)))
the icon is loaded with:
pub static ref DOCK_LEFT_SVG: Image<'static> = Image::new(egui::include_image!("../../data/icons/dock_left.svg"));
The file is:
<svg width="56" height="56" fill="#ffffff" xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M180-120q-24.75 0-42.375-17.625T120-180v-600q0-24.75 17.625-42.375T180-840h600q24.75 0 42.375 17.625T840-780v600q0 24.75-17.625 42.375T780-120H180Zm207-60h393v-600H387v600Z"/></svg>
I had the issue with the old API as well - the solution was to double the width/height in the SVG and it looked sharp.
fit_to_exact_size needs to value the pixels_per_point setting - or did I do something wrong on my side?. When I double the size_points the image becomes larger - not sharper btw.
The text was updated successfully, but these errors were encountered: