-
Notifications
You must be signed in to change notification settings - Fork 1
Images
All images in ImGui.Forms are represented by an ImageResource
.
They hold information to later retrieve a native pointer to that image in Dear ImGui.
It supports most common image formats, like png, jpg, etc.
Only the Icon
in Form takes an Image<Rgba32>
from ImageSharp
directly.
To load an image into ImGui.Forms:
ImageResource.FromFile(@"path/image.png");
ImageResource.FromResource(@"resource.image.png");
ImageResource.FromResource(Assembly.GetExecutingAssembly(), @"resource.image.png");
var imageStream = File.OpenRead(@"path/image.png");
ImageResource.FromStream(imageStream);
var image = Image.Load<Rgba32>(@"path/image.png");
ImageResource.FromImage(image);
It is recommended to use the method, that is most readable for the respective use cases.
An ImageResource
is explicitly convertible to nint
for direct usage in Dear ImGui draw calls.
-
Size
: The original size of the loaded image -
Width
: The original width of the loaded image; Equal toSize.X
-
Height
: The original height of the loaded image; Equal toSize.Y
-
Destroy
: Unloads and frees the image data from Dear ImGui
Certain components take a ThemedImageResource
instead.
Like with ThemedColor, they enable theme switching for image resources.
Set a single image for a specific component's image property:
pictureBox.Image = ImageResource.FromFile(@"path/image.png");
Set a color for every theme for a specific component's color property:
var lightImage = ImageResource.FromFile(@"path/dark.png");
var darkImage = ImageResource.FromFile(@"path/dark.png");
pictureBox.Image = new ThemedImageResource(lightImage, darkImage);
A ThemedImageResource
is explicitly convertible to nint
for direct usage in Dear ImGui draw calls.
It assumes the current theme to retrieve the nint
of the image resource.
An ImageResource
is implicitly convertible to ThemedImageResource
for easier assignment to such properties.
That image resource is set for every theme and therefore doesn't change when switching themes.
-
Size
: The original size of the image for the current theme -
Width
: The original width of the image for the current theme; Equal toSize.X
-
Height
: The original height of the mage for the current theme; Equal toSize.Y
-
Destroy
: Unloads and frees the image data from Dear ImGui
Provides embedded, themed images for usage in components and dialogs, provided by ImGui.Forms.
-
Error
: An error symbol, used in error dialogs