Question

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.

Was it helpful?

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.

OTHER TIPS

create a bitmap of the correct size for your button and change the color of the pixels to your rbga color.

For instance:

     Bitmap image1 = gcnew Bitmap(160,160);
     int x;
     int y;

     Color pixelColor =  Color::FromArgb( A, R, B, G );
     // Loop through the images pixels to reset color. 
     for ( x = 0; x < image1->Width; x++ )
     {
        for ( y = 0; y < image1->Height; y++ )
        {
           image1->SetPixel( x, y, pixelColor );

        }

     }

You could also get a graphics context for the bitmap and use the Graphics.FillRectangle method to fill it.

A bitmap is an image, so you can then set it as your button's image

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top