Image
Native image.
| Header | #include "nativeui/gfx/image.h" |
| Namespace | namespace nu |
| Type | class (RefCounted) |
High DPI Image
By appending @{scaleFactor}x to the image's base filename, you can mark
the image as a high DPI image. For example an image file with filename of
icon@2x.png will have scale factor of 2.
Template Image
On macOS you can mark an image as template image by putting Template to
its base filename, for example iconTemplate.png and iconTemplate@2x.png.
Template images should consist of only black and clear colors, and macOS will mix with other content to create best appearance. This is useful for tray icons and menu item icons that automatically adjust to light and dark themes.
Constructors
Image()
Create an empty image.
Image(const base::FilePath& path)
Create an image by reading from path.
Parameters
const base::FilePath&path
Image(const Buffer& buffer, float scale_factor)
Create an image from buffer in memory, with scale_factor.
Parameters
const Buffer&bufferfloatscale_factor
Methods
void Clear()
Make the image empty.
On Windows creating an image from filesystem path will also lock the file, by calling this method the image file will be unlocked. The original image file will not be modified, and APIs that accepted this image will not be affected.
bool IsEmpty() const
Return whether the image has any data.
Return
boolvoid SetTemplate(bool is)
Set whether the image is a template image.
Parameters
boolis
bool IsTemplate() const
Return whether the image is a template image.
Return
boolSizeF GetSize() const
Return image's size in DIP.
Return
SizeFfloat GetScaleFactor() const
Return image's scale factor.
Return
floatImage* Tint(Color color) const
Return a new image that has tint color applied.
On Windows the tint color is applied by using color matrix, while other
platforms use SourceAtop blend mode. So the result image
might very likely look different on Windows.
Parameters
Colorcolor
Return
Image*Image* Resize(SizeF new_size, float scale_factor) const
Return a new image resized to new_size with scale_factor.
Parameters
SizeFnew_sizefloatscale_factor
Return
Image*Buffer ToPNG() const
Return a buffer containing the image's PNG encoded data.
Return
BufferBuffer ToJPEG(int quality) const
Return a buffer containing the image's JPEG encoded data.
Parameters
intquality - Between 1-100.
Return
BufferNativeImage GetNative() const
Return the native instance wrapped by the class.
Return
NativeImage