Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change transparency of a color in c#

Tags:

I am using SSRS reportviewer to generate a report using objects. In my program, I am asking the user to input a string of commonly known colors such as "Red", "Blue", etc. I would like to then generate three shades of this color and use this color to fill an area chart in my report. I do so my changing the opacity (alpha) of the color.

This is my code that converts the string to color:

 newitem.ChartColor = "red";  Color mycolor = Color.FromName(newitem.ChartColor); 

However, now I would like to generate two more colors with same shade as red but different alpha (opacity) so that they appear lighter, something like #56FF0000

I tried passing a value to the A property of Color however, it is read-only.

Any help appreciated.

like image 693
Shruti Kapoor Avatar asked Jul 19 '13 18:07

Shruti Kapoor


People also ask

How do I make a color code transparent?

When you have a 6 digit color code e.g. #ffffff, replace it with #ffffff00. Just add 2 zeros at the end to make the color transparent.

What is the Colour code for transparent?

You can actually apply a hex code color that is transparent. The hex code for transparent white (not that the color matters when it is fully transparent) is two zeros followed by white's hex code of FFFFFF or 00FFFFFF.

How do you make a color transparent?

Double-click the picture, and when Picture Tools appears, click Picture Tools Format > Color. Click Set Transparent Color, and when the pointer changes, click the color you want to make transparent.

How do I change background color opacity?

Changing the opacity of the background color only To achieve this, use a color value which has an alpha channel—such as rgba. As with opacity , a value of 1 for the alpha channel value makes the color fully opaque. Therefore background-color: rgba(0,0,0,. 5); will set the background color to 50% opacity.


2 Answers

There is a method that does exactly what you need Color.FromArgb(int alpha, Color baseColor).

Valid alpha values are 0 through 255. Where 255 is the most opaque color and 0 a totally transparent color.

Use example

Color newColor = Color.FromArgb(newAlpha, mycolor); 
like image 194
Ma3x Avatar answered Sep 28 '22 00:09

Ma3x


I think what needs to be included among these answers is that the alpha value indicates how transparent the color is with 0 being the most transparent and with 255 being the most opaque. Here is a summary:

                     A L P H A    V A L U E 0 [<--- most transparent]  ... ... ... [most opaque --->] 255 
like image 31
Jazimov Avatar answered Sep 28 '22 00:09

Jazimov