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.
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.
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.
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.
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.
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);
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With