xtd 0.2.0
xtd::drawing::icon Class Reference

Definition

Represents a Windows icon, which is a small bitmap image that is used to represent an object. Icons can be thought of as transparent bitmaps, although their size is determined by the system.

class drawing_export_ icon : public xtd::object
Inheritance
xtd::objectxtd::drawing::icon
Namespace
xtd::drawing
Library
xtd.drawing
Examples:
minesweeper.cpp, and stopwatch_form.cpp.

Fileds

static icon empty
 

Constructors

 icon (const xtd::ustring &filename)
 Initializes a new instance of the xtd::drawing::icon class from the specified file name. More...
 
 icon (const xtd::ustring &filename, const xtd::drawing::size &size)
 Initializes a new instance of the xtd::drawing::icon class of the specified size from the specified file. More...
 
 icon (const xtd::ustring &filename, int32 width, int32 height)
 Initializes a new instance of the xtd::drawing::icon class with the specified width and height from the specified file. More...
 
 icon (std::istream &stream)
 Initializes a new instance of the xtd::drawing::icon class from the specified data stream. More...
 
 icon (std::istream &stream, const xtd::drawing::size &size)
 Initializes a new instance of the xtd::drawing::icon class of the specified size from the specified stream. More...
 
 icon (std::istream &stream, int32 width, int32 height)
 Initializes a new instance of the xtd::drawing::icon class from the specified data stream and with the specified width and height. More...
 
 icon (const char *const *bits)
 Initializes a new instance of the xtd::drawing::icon class from the specified data. More...
 
 icon (const char *const *bits, const xtd::drawing::size &size)
 Initializes a new instance of the xtd::drawing::icon class of the specified size from the specified data. More...
 
 icon (const char *const *bits, int32 width, int32 height)
 Initializes a new instance of the xtd::drawing::icon class from the specified data and with the specified width and height. More...
 
 icon (const icon &original, const xtd::drawing::size &size)
 Initializes a new instance of the xtd::drawing::icon class and attempts to find a version of the icon that matches the requested size. More...
 
 icon (const icon &original, int32 width, int32 height)
 Initializes a new instance of the xtd::drawing::icon class and attempts to find a version of the icon that matches the requested size. More...
 

Properties

intptr handle () const noexcept
 Gets the handle of this icon. This is not a copy of the handle; do not free it. More...
 
int32 height () const noexcept
 Gets the height of this xtd::drawing::icon. More...
 
const xtd::drawing::sizesize () const noexcept
 Gets the size of this xtd::drawing::icon. More...
 
int32 width () const noexcept
 Gets the width of this xtd::drawing::icon. More...
 

Methods

bool equals (const icon &icon) const noexcept override
 
void save (const xtd::ustring &filename) const
 Saves this xtd::drawing::icon to the specified output filename. More...
 
void save (std::ostream &stream) const
 Saves this xtd::drawing::icon to the specified output std::ostream. More...
 
xtd::drawing::bitmap to_bitmap () const
 Converts this xtd::drawing::icon to a GDI+ xtd::drawing::bitmap. More...
 
xtd::ustring to_string () const noexcept override
 Gets a human-readable string that describes the xtd::drawing::icon. More...
 
static icon from_handle (intptr handle)
 Creates a GDI+ xtd::drawing::icon from the specified Windows handle to an icon (HICON). More...
 
static icon from_bitmap (const xtd::drawing::bitmap &bitmap)
 Creates a GDI+ xtd::drawing::icon from the specified bitmap. More...
 

Additional Inherited Members

- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object. More...
 
bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object. More...
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type. More...
 
virtual type_object get_type () const noexcept
 Gets the type of the current instance. More...
 
template<typename object_t >
std::unique_ptr< object_t > memberwise_clone () const noexcept
 Creates a shallow copy of the current object. More...
 
- Public Member Functions inherited from xtd::iequatable< icon >
virtual bool equals (const icon &) const noexcept=0
 Indicates whether the current object is equal to another object of the same type. More...
 
- Static Public Member Functions inherited from xtd::object
static bool equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are considered equal. More...
 
static bool reference_equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are the same instance. More...
 

Constructor & Destructor Documentation

◆ icon() [1/11]

xtd::drawing::icon::icon ( const xtd::ustring filename)
explicit

Initializes a new instance of the xtd::drawing::icon class from the specified file name.

Parameters
filenameThe file to load the xtd::drawing::icon from.
Remarks
An icon resource can contain multiple icon images. One icon file may contain images in several sizes and color depths. The image that is used in an application depends on the operating system and settings. The following list details the typical sizes for an icon:
  • 16 pixels x 16 pixels
  • 32 pixels x 32 pixels
  • 48 pixels x 48 pixels
This constructor returns the smallest image that is contained in the specified file.

◆ icon() [2/11]

xtd::drawing::icon::icon ( const xtd::ustring filename,
const xtd::drawing::size size 
)

Initializes a new instance of the xtd::drawing::icon class of the specified size from the specified file.

Parameters
filenameThe file to load the xtd::drawing::icon from.
sizeThe desired size of the icon.
Remarks
If the specified file does not contain an image that matches the desired size, the icon that has the closest size is returned.
The filename should include the complete path if it is not in the current application directory.

◆ icon() [3/11]

xtd::drawing::icon::icon ( const xtd::ustring filename,
int32  width,
int32  height 
)

Initializes a new instance of the xtd::drawing::icon class with the specified width and height from the specified file.

Parameters
filenameThe file to load the xtd::drawing::icon from.
widthThe desired width of the xtd::drawing::icon.
heightThe desired height of the xtd::drawing::icon.
Remarks
If the specified file does not contain an image that matches the desired height and width, the icon that has the closest size is returned.
The filename should include the complete path if it is not in the current application directory.

◆ icon() [4/11]

xtd::drawing::icon::icon ( std::istream &  stream)
explicit

Initializes a new instance of the xtd::drawing::icon class from the specified data stream.

Parameters
streamThe data stream from which to load the xtd::drawing::icon.
Remarks
An icon resource can contain multiple icon images. One icon file may contain images in several sizes and color depths. The image that is used in an application depends on the operating system and settings. The following list details the typical sizes for an icon:
  • 16 pixels x 16 pixels
  • 32 pixels x 32 pixels
  • 48 pixels x 48 pixels
This constructor returns the smallest image that is contained in the specified stream.

◆ icon() [5/11]

xtd::drawing::icon::icon ( std::istream &  stream,
const xtd::drawing::size size 
)

Initializes a new instance of the xtd::drawing::icon class of the specified size from the specified stream.

Parameters
streamThe data stream from which to load the xtd::drawing::icon.
sizeThe desired size of the icon.

◆ icon() [6/11]

xtd::drawing::icon::icon ( std::istream &  stream,
int32  width,
int32  height 
)

Initializes a new instance of the xtd::drawing::icon class from the specified data stream and with the specified width and height.

Parameters
streamThe data stream from which to load the xtd::drawing::icon.
widthThe width, in pixels, of the icon.
heightThe height, in pixels, of the icon.

◆ icon() [7/11]

xtd::drawing::icon::icon ( const char *const *  bits)
explicit

Initializes a new instance of the xtd::drawing::icon class from the specified data.

Parameters
streamThe data stream from which to load the xtd::drawing::icon.
Remarks
An icon resource can contain multiple icon images. One icon file may contain images in several sizes and color depths. The image that is used in an application depends on the operating system and settings. The following list details the typical sizes for an icon:
  • 16 pixels x 16 pixels
  • 32 pixels x 32 pixels
  • 48 pixels x 48 pixels
This constructor returns the smallest image that is contained in the specified data.
This constructor is used for creating a xtd::drawing::icon from an xpm (or xbm) image.

◆ icon() [8/11]

xtd::drawing::icon::icon ( const char *const *  bits,
const xtd::drawing::size size 
)

Initializes a new instance of the xtd::drawing::icon class of the specified size from the specified data.

Parameters
streamThe data stream from which to load the xtd::drawing::icon.
sizeThe desired size of the icon.
Remarks
This constructor is used for creating a xtd::drawing::icon from an xpm (or xbm) image.

◆ icon() [9/11]

xtd::drawing::icon::icon ( const char *const *  bits,
int32  width,
int32  height 
)

Initializes a new instance of the xtd::drawing::icon class from the specified data and with the specified width and height.

Parameters
streamThe data stream from which to load the xtd::drawing::icon.
widthThe width, in pixels, of the icon.
heightThe height, in pixels, of the icon.
Remarks
This constructor is used for creating a xtd::drawing::icon from an xpm (or xbm) image.

◆ icon() [10/11]

xtd::drawing::icon::icon ( const icon original,
const xtd::drawing::size size 
)

Initializes a new instance of the xtd::drawing::icon class and attempts to find a version of the icon that matches the requested size.

Parameters
originalThe xtd::drawing::icon from which to load the newly sized icon.
sizeA xtd::drawing::size structure that specifies the height and width of the new xtd::drawing::icon.
Remarks
If a version cannot be found that exactly matches the size, the closest match is used. If the original parameter is an xtd::drawing::icon that has a single size, this method only creates a duplicate icon. Use the stretching capabilities of the xtd::graphics::drawing::draw_image method to resize the icon.

◆ icon() [11/11]

xtd::drawing::icon::icon ( const icon original,
int32  width,
int32  height 
)

Initializes a new instance of the xtd::drawing::icon class and attempts to find a version of the icon that matches the requested size.

Parameters
originalThe xtd::drawing::icon from which to load the newly sized icon.
widthThe width of the new icon.
heightThe height of the new icon.
Remarks
If a version cannot be found that exactly matches the size, the closest match is used. If the original parameter is an xtd::drawing::icon that has a single size, this method only creates a duplicate icon. Use the stretching capabilities of the xtd::graphics::drawing::draw_image method to resize the icon.

Member Function Documentation

◆ from_bitmap()

static icon xtd::drawing::icon::from_bitmap ( const xtd::drawing::bitmap bitmap)
static

Creates a GDI+ xtd::drawing::icon from the specified bitmap.

Parameters
bitmapA xtd::drawing::bitmap use to create xtd::drawing::icon.
Returns
The xtd::drawing::icon this method creates.

◆ from_handle()

static icon xtd::drawing::icon::from_handle ( intptr  handle)
static

Creates a GDI+ xtd::drawing::icon from the specified Windows handle to an icon (HICON).

Parameters
handleA Windows handle to an icon.
Returns
The xtd::drawing::icon this method creates.
Remarks
When using this method, you must dispose of the original icon by using the DestroyIcon method in the Windows API to ensure that the resources are released.

◆ handle()

intptr xtd::drawing::icon::handle ( ) const
noexcept

Gets the handle of this icon. This is not a copy of the handle; do not free it.

Returns
The Windows handle for the icon.

◆ height()

int32 xtd::drawing::icon::height ( ) const
noexcept

Gets the height of this xtd::drawing::icon.

Returns
The height of this xtd::drawing::icon.

◆ save() [1/2]

void xtd::drawing::icon::save ( const xtd::ustring filename) const

Saves this xtd::drawing::icon to the specified output filename.

Parameters
filenameThe file to save to.

◆ save() [2/2]

void xtd::drawing::icon::save ( std::ostream &  stream) const

Saves this xtd::drawing::icon to the specified output std::ostream.

Parameters
streamThe std::ostream to save to.

◆ size()

const xtd::drawing::size& xtd::drawing::icon::size ( ) const
noexcept

Gets the size of this xtd::drawing::icon.

Returns
The size of this xtd::drawing::icon.

◆ to_bitmap()

xtd::drawing::bitmap xtd::drawing::icon::to_bitmap ( ) const

Converts this xtd::drawing::icon to a GDI+ xtd::drawing::bitmap.

Returns
A Bitmap that represents the converted xtd::drawing::icon.
Remarks
The transparent areas of the icon are lost when it is converted to a bitmap, and the transparent color of the resulting bitmap is set to RGB(13,11,12). The returned bitmap has the same height and width as the original icon.

◆ to_string()

xtd::ustring xtd::drawing::icon::to_string ( ) const
overridevirtualnoexcept

Gets a human-readable string that describes the xtd::drawing::icon.

Returns
A string that describes the xtd::drawing::icon.

Reimplemented from xtd::object.

Examples:
application_enable_dark_mode.cpp, application_enable_light_mode.cpp, some_controls.cpp, some_system_controls.cpp, and themes.cpp.

◆ width()

int32 xtd::drawing::icon::width ( ) const
noexcept

Gets the width of this xtd::drawing::icon.

Returns
The width of this xtd::drawing::icon.

The documentation for this class was generated from the following file: