I have a Color
, and I have a method that should return a more "transparent" version of that color. I tried the following method:
public static Color SetTransparency(int A, Color color)
{
return Color.FromArgb(A, color.R, color.G, color.B);
}
but for some reason, no matter what the A
is, the returned Color
's transparency level just won't change.
Any idea?
Paint has an option of 'Transparent Selection' under 'Select' drop-down, which claims to make the background color of the selected area of the image transparent or opaque. Please follow these steps: Open image in paint. In Image Section under Select Option Select 'Transparent selection'
Open the image you wish to use in Paint on your computer. Next, click on Select on the left-hand side of the bar located at the top of your page. Select the Transparent Selection option from the available list.
When making images, color can be transparent, where light passes through the colors to the color underneath, making them clearly visible. Color can be translucent, where light is partially passing through to the color underneath, making it partially visible.
Well, it looks okay to me, except that you're using Color.R
(etc) instead of color.R
- are you sure you're actually using the returned Color
rather than assuming it will change the existing color? How are you determining that the "transparency level" won't change?
Here's an example showing that the alpha value is genuinely correct in the returned color:
using System;
using System.Drawing;
class Test
{
static Color SetTransparency(int A, Color color)
{
return Color.FromArgb(A, color.R, color.G, color.B);
}
static void Main()
{
Color halfTransparent = SetTransparency(127, Colors.Black);
Console.WriteLine(halfTransparent.A); // Prints 127
}
}
No surprises there. It would be really helpful if you'd provide a short but complete program which demonstrates the exact problem you're having. Are you sure that whatever you're doing with the color even supports transparency?
Note that this method effectively already exists as Color.FromArgb(int, Color)
.
Just use the correct overload of FromArgb
var color = Color.FromArgb(50, Color.Red);
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