Function egui_extras::install_image_loaders
source · pub fn install_image_loaders(ctx: &Context)
Expand description
Installs a set of image loaders.
Calling this enables the use of egui::Image
and egui::Ui::image
.
⚠ This will do nothing and you won’t see any images unless you also enable some feature flags on egui_extras
:
file
feature:file://
loader on non-Wasm targetshttp
feature:http(s)://
loaderimage
feature: Loader of png, jpeg etc using theimage
cratesvg
feature:.svg
loader
Calling this multiple times on the same egui::Context
is safe.
It will never install duplicate loaders.
- If you just want to be able to load
file://
andhttp://
URIs, enable theall_loaders
feature. - The supported set of image formats is configured by adding the
image
crate as your direct dependency, and enabling features on it:
egui_extras = { version = "*", features = ["all_loaders"] }
image = { version = "0.24", features = ["jpeg", "png"] } # Add the types you want support for
⚠ You have to configure both the supported loaders in egui_extras
and the supported image formats
in image
to get any output!
Loader-specific information
⚠ The exact way bytes, images, and textures are loaded is subject to change, but the supported protocols and file extensions are not.
The file
loader is a BytesLoader
.
It will attempt to load file://
URIs, and infer the content type from the extension.
The path will be passed to std::fs::read
after trimming the file://
prefix,
and is resolved the same way as with std::fs::read(path)
:
- Relative paths are relative to the current working directory
- Absolute paths are left as is.
The http
loader is a BytesLoader
.
It will attempt to load http://
and https://
URIs, and infer the content type from the Content-Type
header.
The image
loader is an ImageLoader
.
It will attempt to load any URI with any extension other than svg
.
It will also try to load any URI without an extension.
The content type specified by BytesPoll::Ready::mime
always takes precedence.
This means that even if the URI has a png
extension, and the png
image format is enabled, if the content type is
not one of the supported and enabled image formats, the loader will return LoadError::NotSupported
,
allowing a different loader to attempt to load the image.
The svg
loader is an ImageLoader
.
It will attempt to load any URI with an svg
extension. It will not attempt to load a URI without an extension.
The content type specified by BytesPoll::Ready::mime
always takes precedence,
and must include svg
for it to be considered supported. For example, image/svg+xml
would be loaded by the svg
loader.
See egui::load
for more information about how loaders work.