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

◆ from_argb() [4/4]

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

Creates a xtd::drawing::color structure from the specified 8-bit color values (red, green, and blue). The alpha value is implicitly 255 (fully opaque). Although this method allows a 32-bit value to be passed for each color component, the value of each component is limited to 8 bits.

Parameters
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 xtd::drawing::color structures from the three color component values (red, green, blue). Three xtd::drawing::color structures are created, one for each primary color.
  • Iterates through a range of alpha values, changing the alpha value of a color.
  • During each iteration, sets the color of a brush to the modified color and paints a rectangle to show the color.
  • Repeats steps 2 and 3 for each primary color. The alpha value is never fully opaque and the rectangles overlap so you get color-combination effects.
    void from_argb2(paint_event_aArgs& e) {
    graphics g = e.graphics();
    // Opaque colors (alpha value defaults to 255 -- max value).
    color red = color::from_argb(255, 0, 0);
    color blue = color::from_argb(0, 0, 255);
    // Solid brush initialized to red.
    solid_brush my_brush(red);
    int alpha;
    // x coordinate of first red rectangle
    int x = 50;
    // y coordinate of first red rectangle
    int y = 50;
    // Fill rectangles with red, varying the alpha value from 25 to 250.
    for (alpha = 25; alpha <= 250; alpha += 25) {
    my_brush.color(color::from_argb(alpha, red));
    g.fill_rectangle(my_brush, x, y, 50, 100);
    g.fill_rectangle(my_brush, x, y + 250, 50, 50);
    x += 50;
    }
    // x coordinate of first green rectangle.
    x = 50;
    // y coordinate of first green rectangle.
    y += 50;
    // Fill rectangles with green, varying the alpha value from 25 to 250.
    for (alpha = 25; alpha <= 250; alpha += 25) {
    my_brush.color(color::from_argb(alpha, green));
    g.fill_rectangle(my_brush, x, y, 50, 150);
    x += 50;
    }
    // x coordinate of first blue rectangle.
    x = 50;
    // y coordinate of first blue rectangle.
    y += 100;
    // Fill rectangles with blue, varying the alpha value from 25 to 250.
    for (alpha = 25; alpha <= 250; alpha += 25) {
    my_brush.color(color::from_argb(alpha, blue));
    g.fill_rectangle(my_brush, x, y, 50, 150);
    x += 50;
    }
    }
    static const xtd::drawing::color green
    Gets a system-defined color that has an ARGB value of 0xFF008000. This field is constant.
    Definition color.h:215
    static const xtd::drawing::color red
    Gets a system-defined color that has an ARGB value of 0xFFFF0000. This field is constant.
    Definition color.h:404
    xtd::byte g() const noexcept
    Gets the green component value of this xtd::drawing::color class.
    static const xtd::drawing::color blue
    Gets a system-defined color that has an ARGB value of 0xFF0000FF. This field is constant.
    Definition color.h:89
    static xtd::drawing::color from_argb(uint32 argb) noexcept
    Creates a xtd::drawing::color class from a 32-bit ARGB value.
    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
    @ y
    The Y key.
    @ x
    The X key.
    @ e
    The E key.