I have 3 rectangles that differ from each other in opacity. The base color is same for all of them. For eg: the base color could be Red and the three rectangles would have the following colors: Red, Red (opacity: 55), Red (opacity: 135).
I tried setting the Background Color of the rectangle but it seems I cannot change the transparency of a rectangle. Is there a workaround for this?
Thank you!
It turns out that this is a limitation of reportviewer. Opacity values can be given to only gauges and graphs. Shapes and fonts do not accept opacity values.
A close workaround to this is to add the opacity value to RGB. For example: if I want to generate a color inRGBA as (255,0,0,160) , I should add 255-160=95 to the values of G and B to get a color close to my needs. Therefore the color turns out to be (255,95,95). It is not the exact color but it is close. I tried this for red, blue and green colors since those are the only colors I need.
I hope this helps someone.
Related
I using a color picker to draw with a pen, but using this code I can't change de opacity of the pen color:
InkDrawingAttributes inkDrawingAttributes = InkCanvas.InkPresenter.CopyDefaultDrawingAttributes();
inkDrawingAttributes.Color = ColorPenSelected;
InkCanvas.InkPresenter.UpdateDefaultDrawingAttributes(inkDrawingAttributes);
This way works well with a pen:
But, using the InkCanvas.InkPresenter.CopyDefaultDrawingAttributes() the inkDrawingAttributes.PencilProperties is null and I can't change the Opacity. It is not allowed to change the opacity.
I could change the opacity with this code:
InkDrawingAttributes inkDrawingAttributes = InkDrawingAttributes.CreateForPencil();
inkDrawingAttributes.Color = ColorPenSelected;
inkDrawingAttributes.PencilProperties.Opacity = (double)ColorPenSelected.A * 5 / 255;
InkCanvas.InkPresenter.UpdateDefaultDrawingAttributes(inkDrawingAttributes);
Using as a pencil in CreateForPencil().
Now, I could change the Opacity. However, the brush texture is different, even using Opacity 100%, compared to the first image. There are many dots in the line, instead an unique line:
So, How can I change the opacity for the Pen brush and keep the same texture as the first image? With a continuous line, without dots as in the second image.
I initially thought that you could set the inkDrawingAttributes.Color as an ARGB value, but this isn't possible for the below reason.
Taken from learn.microsoft.com
The value of Color is an ARGB value. However, the value of the
transparency component (A, or alpha channel) is ignored and the
InkStroke is rendered at full opacity.
I'm afraid it would seem that this isn't possible. You could perhaps render the stroke as semi transparent afterwards - But doesn't seem like you can set the opacity of the pen.
I have image:
Image<Bgr,Byte> someImage = new Image<Bgr,Byte>(someImage.jpg);
How can I make all black pixels(black color) transparent?
Thank you in advance.
You can see an example about how to use alpha to make background transparent on this thread.
You will need to find a way to define your image in such a way that it uses the alpha channel. If you want details, this is the link for RGBA color space.
Basically, you need to initialize a CV_8UC4 image. Keep in mind to initialize all pixels to zero before you start (basically, the entire matrix will be black before you start putting values in)..
I'm using the Brushes in my wpf application as shown below, what I want to do is to control the colour intensity. So as shown below the brush is set to Green colour. But what I want to do is to control the intensity of the green colour, so that sometimes it can be lighter or thicker, depending on the value I pass it. so if anyone could please advise.
private readonly Pen P = new Pen(Brushes.Green, 6);
You could create your own brush:
private readonly Pen p = new Pen(new SolidColorBrush(Color.FromARGB(...)), 6);
You can then define the color exactly by passing alpha, red, green and blue components to Color.FromARGB.
An easy solution would be to just manipulate the A-value of a green color like so:
int a = yourAValue;
private readonly Pen p = new Pen(new SolidColorBrush(Color.FromARGB(a,0,255,0)), 6);
Now you can change the colors intensity by changing the a-value;
You could use the HSL colour model instead of RGB. RGB is good for displays as it is based upon mixing the three primary colours of light. However, it doesn't fit well with the human model.
HSL's elements are hue, saturation and lightness. This does fit with the way we describe colours in real life. Adjusting the hue changes the colour - keeping the hue the same and modifiying the other elements gives a colour that varies but that a person would see as being related.
Varying the saturation changes the deepness of the colour. A saturation of zero removes the colour and you end up with a greyscale. A higher saturation makes the colour more vivid. The lightness is what it says. A lightness of zero always gives black. A lightness of the maximum value is white. In between the two extremes are your colours.
Unfortunately HSL is not natively supported by WPF / .NET. However, it's quite easy to create your own method to convert between RGB and HSL. This would probably work well within a method or value converter in your case.
I wrote an article about the conversion on my web site. There's also a downloadable sample and source code for the conversion that you can use for free (you just have to promise not to sue me if something goes wrong!). It's at http://www.blackwasp.co.uk/RGBHSL.aspx
Please see this blog post for an HSL Color implementation for WPF, and a XAML markup extension to lighten/darken colors.
I am developing an application where I have to play around with some RGB colors. Actually, I have RGB and its HEX/HSV equivalent.
Now, I am trying to dynamically generate matching colors for a selected color, lets say 'Red', then I would like to generates 5 matching colors for red, ex: black, orange, other teint of red, some blue, etc...
I don't have knowledge about how colors and their calculation work, so any help, hints, code snippets would be greatly appreciated.
HSV is a much better colorspace to manipulate colors in than RGB, because HSV's axes correspond directly to useful transformations of a color.
To make a color brighter or more saturated, increase its saturation. To desaturate (make grayscale), decrease the saturation. Decreasing the V(alue) of a color makes it darker - all colors with V of 0 are black. Changing the hue alters the color itself, moving around a color wheel. See Wikipedia's article on HSV for more details.
What transformations you do depend on what sort of related colors you want to generate. If you want complementary colors, for instance, you probably want to take the color, leave the S and V unmodified, and generate colors 1/3rd and 2/3rds of the way around the color wheel from the current color. Brighter and darker versions can be made by varying the value, while more and less 'intense' colors can be made by varying the saturation.
RGB colors are just a space in memory where you have three values, each ranging from 0 to 255. Red, for example, is just 255, 0, 0... 255 (maximum) in the "Red" field of the memory location, and zero in the "Blue" and "Green". It's when you mix these different values around that you start to get the almost infinite array of colors we see on our screens.
I can't quite tell you what to do with your code without seeing it, but I can tell you that if you have a control or object where you have a RGB property, you can modify the values in said property to make the color of the control or object any color you want. Experiment to see what values produce the colors you want, then enter these into the property fields in the dynamic manner that you seek.
I have a TextBox that displays a color as its background color and the background color code in its text. I have set the text color as Black.
The problem is that if the user sets the color as Black then the color code will be unreadable. How do I set the text color programmatically so that it becomes readable when the user selects any color?
You can use negative color for the text:
Color InvertColor(Color sourceColor) {
return Color.FromArgb(255 - sourceColor.R,
255 - sourceColor.G,
255 - sourceColor.B);
}
Any color is guaranteed to be more or less readable on its negative color, so there you go. This is a quick and dirty way to invert a color, you may also want to check the answers for this question: How do I invert a color?
Another option is to add a white halo to the black text. That's what people do in GIS applications to ensure that map labels are readable on top of any surface. The idea of halo effect is to have a thin white border around black text. This way the text is readable whether it's on white background (the border becomes invisible) or on black background (the border outlines the text).
There are multiple tutorials on the topic, like this article or this SO question (with VB.NET sample).
When you have a Color picked out, just assign it to the ForeColor property of your textbox like this:
txtColor.ForeColor = mycolor;
Not working on Gray color.
This code is more usable:
lblCarColor.BackColor = color;
if ((color.B + color.R + color.G) / 3 <= 128)
{
lblCarColor.ForeColor = Color.White;
}