xtd 0.2.0
Loading...
Searching...
No Matches

◆ to_argb()

uint32 xtd::drawing::color::to_argb ( ) const
noexcept

Gets the 32-bit ARGB value of this xtd::drawing::color class.

Returns
The 32-bit ARGB value of this xtd::drawing::color.
Remarks
The byte-ordering of the 32-bit ARGB value is AARRGGBB. The most significant byte (MSB), represented by AA, is the alpha component value. The second, third, and fourth bytes, represented by RR, GG, and BB, respectively, are the color components red, green, and blue, respectively.
Examples
The following code example is designed for use with Windows Forms, and it requires xtd::forms::paint_event_args e, which is a parameter of the xtd::forms::control::paint event handler. The code performs the following actions:
  • Iterates through the xtd::drawing::known_color enumeration elements to find all known colors that have a non-zero green component and a zero-value red component, and that are not system colors.
  • During each iteration, saves the xtd::drawing::known_color element - if it matches the criteria - in an array.
  • Uses a brush to paint rectangles. Each of the rectangles is painted a xtd::drawing::known_color that matches the criteria stated in the first bullet. The name of the xtd::drawing::known_color and its component values are also displayed. This example displays certain known colors, the names of the colors, and their four component values. The xtd::drawing::color::to_argb method is used as a preliminary step to display the component values.
    void to_argb_to_string_example1(paint_event_args& e) {
    graphics g = e.graphics();
    // Color structure used for temporary storage.
    color some_color = color::from_argb(0);
    // Vector to store known_color values that match the criteria.
    std::vector<known_color> color_matches;
    // Iterate through the KnownColor enums to find all corresponding colors
    // that have a nonzero green component and zero-value red component and
    // that are not system colors.
    for (int enum_value = 0; enum_value <= static_cast<int>(known_color::yellow_green); ++enum_value) {
    some_color = color::from_known_color(static_cast<known_color>(enum_value));
    if (some_color.g() != 0 && some_color.r() == 0 && !some_color.is_system_color())
    color_matches.emplace_back(static_cast<known_color>(enum_value));
    }
    solid_brush my_brush1 {some_color};
    font my_font {"Arial", 9};
    int x = 40;
    int y = 40;
    // Iterate through the matches that were found and display each color that
    // corresponds with the enum value in the array. also display the name of
    // the known_color and the ARGB components.
    for (size_t i = 0; i < color_matches.size(); ++i) {
    // Display the color.
    some_color = color::from_known_color(color_matches[i]);
    my_brush1.color(some_color);
    g.fill_rectangle(my_brush1, x, y, 50, 30);
    // Display known_color name and the four component values. To display the
    // component values: Use the to_argb method to get the 32-bit ARGB value
    // of some_color, which was created from a known_color. Then create a
    // color structure from the 32-bit ARGB value and set some_color equal to
    // this new color structure. Then use the to_string method to convert it to
    // a string.
    g.draw_string(some_color.to_string(), my_font, brushes::black(), x + 55, y);
    some_color = color::from_argb(some_color.to_argb());
    g.draw_string(some_color.to_string(), my_font, brushes::black(), x + 55, y + 15);
    y += 40;
    }
    }
    static xtd::drawing::solid_brush black()
    A system-defined brush object.
    static xtd::drawing::color from_known_color(xtd::drawing::known_color color)
    Creates a xtd::drawing::color class from the four ARGB component (alpha, red, green,...
    uint32 to_argb() const noexcept
    Gets the 32-bit ARGB value of this xtd::drawing::color class.
    xtd::byte r() const noexcept
    Gets the red component value of this xtd::drawing::color class.
    xtd::byte g() const noexcept
    Gets the green component value of this xtd::drawing::color class.
    static xtd::drawing::color from_argb(uint32 argb) noexcept
    Creates a xtd::drawing::color class from a 32-bit ARGB value.
    xtd::string to_string() const noexcept override
    Creates a human-readable string that represents this color class.
    bool is_system_color() const noexcept
    Gets a value indicating whether this xtd::drawing::color structure is a system color....
    Represents an ARGB (alpha, red, green, blue) color.
    Definition color.h:49
    Defines an object used to draw lines and curves. This class cannot be inherited.
    Definition graphics.h:70
    Defines a xtd::drawing::brush of a single color. Brushes are used to fill graphics shapes,...
    Definition solid_brush.h:30
    known_color
    Specifies the known system colors.
    Definition known_color.h:18
    @ yellow_green
    A system-defined color.
    @ y
    The Y key.
    @ i
    The I key.
    @ x
    The X key.
    @ e
    The E key.