Skip to content
realonepiecefreak edited this page Oct 3, 2024 · 3 revisions

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.

ImageResource

It supports most common image formats, like png, jpg, etc.

Only the Icon in Form takes an Image<Rgba32> from ImageSharp directly.

Usage

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.

Properties

  • Size: The original size of the loaded image
  • Width: The original width of the loaded image; Equal to Size.X
  • Height: The original height of the loaded image; Equal to Size.Y

Methods

  • Destroy: Unloads and frees the image data from Dear ImGui

ThemedImageResource

Certain components take a ThemedImageResource instead.
Like with ThemedColor, they enable theme switching for image resources.

Usage

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.

Properties

  • Size: The original size of the image for the current theme
  • Width: The original width of the image for the current theme; Equal to Size.X
  • Height: The original height of the mage for the current theme; Equal to Size.Y

Methods

  • Destroy: Unloads and frees the image data from Dear ImGui

ImageResources

Provides embedded, themed images for usage in components and dialogs, provided by ImGui.Forms.

  • Error: An error symbol, used in error dialogs
Clone this wiki locally