简体   繁体   English

更改笔刷的 InkDrawingAttributes 不透明度

[英]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 inkDrawingAttributes = InkCanvas.InkPresenter.CopyDefaultDrawingAttributes(); inkDrawingAttributes.Color = ColorPenSelected; inkDrawingAttributes.Color = ColorPenSelected; InkCanvas.InkPresenter.UpdateDefaultDrawingAttributes(inkDrawingAttributes); 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.但是,使用 InkCanvas.InkPresenter.CopyDefaultDrawingAttributes() inkDrawingAttributes.PencilProperties 是 null,我无法更改不透明度。 It is not allowed to change the opacity.不允许更改不透明度。

I could change the opacity with this code:我可以用这段代码改变不透明度:

InkDrawingAttributes inkDrawingAttributes = InkDrawingAttributes.CreateForPencil(); InkDrawingAttributes inkDrawingAttributes = InkDrawingAttributes.CreateForPencil(); inkDrawingAttributes.Color = ColorPenSelected; inkDrawingAttributes.Color = ColorPenSelected; inkDrawingAttributes.PencilProperties.Opacity = (double)ColorPenSelected.A * 5 / 255; inkDrawingAttributes.PencilProperties.Opacity = (double)ColorPenSelected.A * 5 / 255; InkCanvas.InkPresenter.UpdateDefaultDrawingAttributes(inkDrawingAttributes); InkCanvas.InkPresenter.UpdateDefaultDrawingAttributes(inkDrawingAttributes);

Using as a pencil in CreateForPencil().在 CreateForPencil() 中用作铅笔。

Now, I could change the Opacity.现在,我可以更改不透明度。 However, the brush texture is different, even using Opacity 100%, compared to the first image.然而,与第一张图像相比,画笔纹理不同,即使使用 100% 的不透明度。 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.我最初认为您可以将inkDrawingAttributes.Color设置为 ARGB 值,但由于以下原因这是不可能的。

Taken from learn.microsoft.com取自learn.microsoft.com

The value of Color is an ARGB value. Color 的值是一个 ARGB 值。 However, the value of the transparency component (A, or alpha channel) is ignored and the InkStroke is rendered at full opacity.但是,透明度组件(A 或 alpha 通道)的值将被忽略,InkStroke 将以完全不透明的方式呈现。

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.您也许可以在之后将笔划渲染为半透明 - 但似乎您无法设置笔的不透明度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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