Reputation: 11
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:
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.
Upvotes: 0
Views: 73
Reputation: 8681
After talking with the team, I have to say that this behavior is expected. The InkStroke of the default pen will always be rendered in full opacity. The InkDrawingAttributes.Color Property accept ARGB values but the value of the transparency component (A, or alpha channel) is ignored.
So you can't change the opacity of the InkDrawingAttributes for the default pen brush.
Upvotes: 0
Reputation: 800
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.
Upvotes: 1