Search code examples
imagebuttonc++-clirgba

How do I create image from rgba?


I get RGBA rgba from ColorDialog. How do I create image from rgba?

I want to set button's image based on user color selection.


Solution

  • You could create a Bitmap, create a Graphics object from it and fill it with any color.

    Bitmap^ bmp = gcnew Bitmap(WIDTH, HEIGHT);
    Graphics^ g = Graphics::FromImage(bmp);
    g->FillRectangle(
       gcnew SolidBrush(Color::FromArgb(alfa, red, green, blue)),
       Rectangle(Point.Empty, bmp.Size() );
    

    So easy.