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

◆ from_argb() [3/4]

static xtd::drawing::color xtd::drawing::color::from_argb ( xtd::byte  alpha,
xtd::byte  red,
xtd::byte  green,
xtd::byte  blue 
)
staticnoexcept

Creates a xtd::drawing::color class from the four ARGB component (alpha, red, green, and blue) values. Although this method allows a 32-bit value to be passed for each component, the value of each component is limited to 8 bits.

Parameters
alphaThe alpha value for the new xtd::drawing::color. Valid values are 0 through 255.
redThe red component. Valid values are 0 through 255.
greenThe green component. Valid values are 0 through 255.
blueThe blue component. Valid values are 0 through 255.
Returns
xtd::drawing::color The xtd::drawing::color structure that this method creates.
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:
  • Creates three brushes, each a different color. Each xtd::drawing::color structure that is used to create a brush is created from four component values (alpha, red, green, blue).
  • Uses an imaginary triangle to position three circles.
  • Paints three overlapping circles, each centered on one vertex of the triangle, using a different brush for each circle.
    void from_argb1(paint_event_args& e) {
    graphics g = e.graphics();
    // Transparent red, green, and blue brushes.
    solid_brush trns_red_brush(color::from_argb(120, 255, 0, 0));
    solid_brush trns_green_brush(color::from_argb(120, 0, 255, 0));
    solid_brush trns_blue_brush(color::from_argb(120, 0, 0, 255));
    // Base and height of the triangle that is used to position the circles. Each vertex of the triangle is at the center of one of the 3 circles. The base is equal to the diameter of the circles.
    float tri_base = 100;
    float tri_height = std::sqrt(3 * (tri_base * tri_base) / 4);
    // Coordinates of first circle's bounding rectangle.
    float x1 = 40;
    float y1 = 40;
    // Fill 3 over-lapping circles. Each circle is a different color.
    g.fill_ellipse(trns_red_brush, x1, y1, 2 * tri_height, 2 * tri_height);
    g.fill_ellipse(trns_green_brush, x1 + tri_base / 2, y1 + tri_height, 2 * tri_height, 2 * tri_height);
    g.fill_ellipse(trns_blue_brush, x1 + tri_base, y1, 2 * tri_height, 2 * tri_height);
    }
    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.
    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
    @ e
    The E key.