简体   繁体   中英

Change InkDrawingAttributes Opacity for Pen brush

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM