S or /

SourceClass Image

from egui import Image
class Image:

A widget which displays an image.

The task of actually loading the image is deferred to when the Image is added to the Ui, and how it is loaded depends on the provided ImageSource:

See egui.load for more information.

Examples

// Using it in a layout:

// Using it just to paint:

Methods§

Sourcedef alt_text(self, /, label: str) -> Image§

Set alt text for the image. This will be shown when the image fails to load.

It will also be used for accessibility (e.g. read by screen readers).

Sourcedef bg_fill(self, /, color: Color32) -> Image§

A solid color to put behind the image. Useful for transparent images.

Sourcedef calc_size(self, /, available_size: Vec2, image_source_size: Vec2 |None) -> Vec2§

Returns the size the image will occupy in the final UI.

Sourcedef corner_radius(self, /, corner_radius: CornerRadius) -> Image§

Round the corners of the image.

The default is no rounding (CornerRadius.ZERO).

Due to limitations in the current implementation, this will turn off any rotation of the image.

Sourcedef fit_to_exact_size(self, /, size: Vec2) -> Image§

Fit the image to an exact size.

If Image.max_size is set, this is guaranteed to never exceed that limit.

Sourcedef fit_to_fraction(self, /, fraction: Vec2) -> Image§

Fit the image to a fraction of the available space.

If Image.max_size is set, this is guaranteed to never exceed that limit.

Sourcedef fit_to_original_size(self, /, scale: float) -> Image§

Fit the image to its original size with some scaling.

The texel size of the source image will be multiplied by the scale factor, and then become the ui size of the Image.

This will cause the image to overflow if it is larger than the available space.

If Image.max_size is set, this is guaranteed to never exceed that limit.

Source@staticmethod def from_bytes(uri: str, bytes: Bytes) -> Image§

Load the image from some raw bytes.

For better error messages, use the bytes:// prefix for the URI.

See ImageSource.Bytes.

Source@staticmethod def from_texture(texture: SizedTexture) -> Image§

Load the image from an existing texture.

See ImageSource.Texture.

Source@staticmethod def from_uri(uri: str) -> Image§

Load the image from a URI.

See ImageSource.Uri.

Sourcedef image_options(self, /) -> ImageOptions§
Sourcedef load_and_calc_size(self, /, ui: Ui, available_size: Vec2) -> Vec2 |None§
Sourcedef load_for_size(self, /, ctx: Context, available_size: Vec2) -> TexturePoll§

Load the image from its Image.source, returning the resulting SizedTexture.

The available_size is used as a hint when e.g. rendering an svg.

Errors

May fail if they underlying Context.try_load_texture call fails.

Sourcedef maintain_aspect_ratio(self, /, value: bool) -> Image§

Whether or not the ImageFit should maintain the image's original aspect ratio.

Sourcedef max_height(self, /, max_height: float) -> Image§

Set the max height of the image.

No matter what the image is scaled to, it will never exceed this limit.

Sourcedef max_size(self, /, max_size: Vec2) -> Image§

Set the max size of the image.

No matter what the image is scaled to, it will never exceed this limit.

Sourcedef max_width(self, /, max_width: float) -> Image§

Set the max width of the image.

No matter what the image is scaled to, it will never exceed this limit.

Sourcedef paint_at(self, /, ui: Ui, rect: Rect) -> None§

Paint the image in the given rectangle.

Sourcedef rotate(self, /, angle: float, origin: Vec2) -> Image§

Rotate the image about an origin by some angle

Positive angle is clockwise. Origin is a vector in normalized UV space ((0,0) in top-left, (1,1) bottom right).

To rotate about the center you can pass Vec2.splat(0.5) as the origin.

Due to limitations in the current implementation, this will turn off rounding of the image.

def rounding(self, /, corner_radius: CornerRadius) -> Image§
Sourcedef sense(self, /, sense: Sense) -> Image§

Make the image respond to clicks and/or drags.

def show(self, /, ui: Ui) -> Response§
Sourcedef show_loading_spinner(self, /, show: bool) -> Image§

Show a spinner when the image is loading.

By default this uses the value of egui.Visuals.image_loading_spinners.

Sourcedef shrink_to_fit(self, /) -> Image§

Fit the image to 100% of its available size, shrinking it if necessary.

This is a shorthand for Image.fit_to_fraction with 1.0 for both width and height.

If Image.max_size is set, this is guaranteed to never exceed that limit.

Sourcedef size(self, /) -> Vec2 |None§
Sourcedef source(self, /, ctx: Context) -> ImageSource§
Sourcedef texture_options(self, /, texture_options: TextureOptions) -> Image§

Texture options used when creating the texture.

Sourcedef tint(self, /, color: Color32) -> Image§

Multiply image color with this. Default is WHITE (no tint).

Sourcedef uri(self, /) -> str |None§

Returns the URI of the image.

For animated images, returns the URI without the frame number.

Sourcedef uv(self, /, uv: Rect) -> Image§

Select UV range. Default is (0,0) in top-left, (1,1) bottom right.