ImageProvider Class
Supports a mechanism for retrieving image variations based on chromatic adaptations (color shifting), theme, DPI, etc.
public class ImageProvider
- Inheritance:
- object object
Constructors
ImageProvider()
Initializes an instance of the class.
public ImageProvider()
Properties
ChromaticAdaptationMode
Gets or sets the chromatic adaptation (color shifting) mode to apply to images.
public ImageChromaticAdaptationMode ChromaticAdaptationMode { get; set; }
Property Value
- ImageChromaticAdaptationMode:
An ImageChromaticAdaptationMode indicating the chromatic adaptation (color shifting) mode to apply to images. The default value is
Never
.
Remarks
Chromatic adaptation is the process of taking an image designed for a light theme and dynamically creating a variation of it that renders clearly on a specified background color, sometimes adjusting the brightness and hue as needed. This feature is useful when wanting to have a single set of original images that can be adjusted at run-time to render well in dark themes. This value should be set prior to UI being loaded.
Default
Gets or sets the default ImageProvider instance.
public static ImageProvider Default { get; set; }
Property Value
- ImageProvider:
The default ImageProvider instance.
DesignForegroundColor
Gets or sets a Color
used in images that when specified, can be swapped out with a Color
specified in ForegroundColor.
public Color? DesignForegroundColor { get; set; }
Property Value
- Color?:
A
Color
used in images that when specified, can be swapped out with aColor
specified in ForegroundColor.
Remarks
This property should generally only be specified when using monochrome vector icons. Specifying a value allows images to switch their foreground dynamically based on a containing control's state (normal, highlighted, etc.). This is necessary when the foreground of the containing control changes drastically and requires an image's foreground to also change to retain a proper contrast ratio.
MonochromeBrightnessThreshold
The brightness threshold to use when generating monochrome image variations.
public byte MonochromeBrightnessThreshold { get; set; }
Property Value
Remarks
Pixels with brightness at or above this threshold will be made transparent.
Pixels with brightness below this threshold will be made a single color, specified in ForegroundColor.
Set this value to 0
to prevent monochrome image variations from being supported.
This value should be set prior to UI being loaded.
RelativePathBaseUri
The base URI to be used when attempting to resolve an image identified by a relative path.
public Uri? RelativePathBaseUri { get; set; }
Property Value
- Uri
Remarks
If most images are defined within a single assembly, this property can be used to identify the base URI for those images and avoids having to use an absolute URI for all images.
Methods
AdaptColor(Color, ImageProviderRequest?)
Adapts the specified Avalonia.Media.Color.
protected virtual Color AdaptColor(Color color, ImageProviderRequest? request)
Parameter | Type | Description |
---|---|---|
color | Color | The Avalonia.Media.Color to adapt. |
request | ImageProviderRequest | An ImageProviderRequest that contains request information. |
Returns
- Color:
The adapted color.
GetCanAdapt(AvaloniaObject)
Gets the value of the CanAdapt
attached property for the specified object.
public static bool GetCanAdapt(AvaloniaObject obj)
Parameter | Type | Description |
---|---|---|
obj | AvaloniaObject | The object from which the property value is read. |
Returns
- bool:
The object's value.
GetColorFromBrush(IBrush?)
Returns the Avalonia.Media.Color associated with the specified Avalonia.Media.IBrush.
public static Color? GetColorFromBrush(IBrush? brush)
Parameter | Type | Description |
---|---|---|
brush | IBrush | The Avalonia.Media.IBrush to examine. |
Returns
- Color?:
The Avalonia.Media.Color associated with the specified Avalonia.Media.IBrush.
GetImageSource(IImage, ImageProviderRequest)
Returns the same, or possibly an alternate variation of the specified Avalonia.Media.IImage, based on the request and the provider's settings.
public virtual IImage? GetImageSource(IImage originalImageSource, ImageProviderRequest request)
Parameter | Type | Description |
---|---|---|
originalImageSource | IImage | The Avalonia.Media.IImage to examine. |
request | ImageProviderRequest | An ImageProviderRequest that contains request information. |
Returns
- IImage:
The same or alternate variation of the specified Avalonia.Media.IImage.
GetImageSource(string)
Returns the image referenced by the given key
.
public virtual IImage? GetImageSource(string key)
Parameter | Type | Description |
---|---|---|
key | string | The key which identifies the image. |
Returns
- IImage:
The Avalonia.Media.IImage identified by the
key
; ornull
if an Avalonia.Media.IImage could not be identified.
See Also
GetImageSource(string, ImageProviderRequest)
Returns the same, or possibly an alternate variation of the image referenced by the given key
, based on the request and the provider's settings.
public virtual IImage? GetImageSource(string key, ImageProviderRequest request)
Parameter | Type | Description |
---|---|---|
key | string | The key which identifies the image. |
request | ImageProviderRequest | An ImageProviderRequest that contains request information. |
Returns
- IImage:
The same or alternate variation of the Avalonia.Media.IImage identified by the
key
; ornull
if an Avalonia.Media.IImage could not be identified.
See Also
GetImageSourceWithColorSwatch(IImage, Rect, Color)
Creates a new Avalonia.Media.IImage that renders a rectangular color swatch on top of a provided Avalonia.Media.IImage.
public static IImage GetImageSourceWithColorSwatch(IImage originalImageSource, Rect swatchBounds, Color color)
Parameter | Type | Description |
---|---|---|
originalImageSource | IImage | The Avalonia.Media.IImage under which to render a color swatch. |
swatchBounds | Rect | The color swatch bounds, relative to the |
color | Color | The Avalonia.Media.Color to render in the swatch. |
Returns
- IImage:
The Avalonia.Media.IImage that was created.
GetProvider(AvaloniaObject)
Gets the value of the Provider
attached property for the specified object.
public static ImageProvider? GetProvider(AvaloniaObject obj)
Parameter | Type | Description |
---|---|---|
obj | AvaloniaObject | The object from which the property value is read. |
Returns
- ImageProvider:
The object's value.
SetCanAdapt(AvaloniaObject, bool)
Sets the value of the CanAdapt
attached property to the specified object.
public static void SetCanAdapt(AvaloniaObject obj, bool value)
Parameter | Type | Description |
---|---|---|
obj | AvaloniaObject | The object to which the attached property is written. |
value | bool | The value to set. |
SetProvider(AvaloniaObject, ImageProvider?)
Sets the value of the Provider
attached property to the specified object.
public static void SetProvider(AvaloniaObject obj, ImageProvider? value)
Parameter | Type | Description |
---|---|---|
obj | AvaloniaObject | The object to which the attached property is written. |
value | ImageProvider | The value to set. |
Fields
CanAdaptProperty
Identifies the CanAdapt
attached property.
public static readonly AttachedProperty<bool> CanAdaptProperty
ProviderProperty
Identifies the Provider
attached property.
public static readonly AttachedProperty<ImageProvider?> ProviderProperty
Inherited Members
- object.GetType()
- object.MemberwiseClone()
- object.ToString()
- object.Equals(object)
- object.Equals(object, object)
- object.ReferenceEquals(object, object)
- object.GetHashCode()