【问题标题】:In Silverlight 4: how to set the Opacity of a Stroke programmatically?在 Silverlight 4 中:如何以编程方式设置描边的不透明度?
【发布时间】:2011-05-12 20:14:38
【问题描述】:

我想设置从用户在屏幕上绘制的 Stroke 的不透明度。我可以设置要设置的笔划的绘图、大小、轮廓,但不能设置它的不透明度。

这是我的代码

StylusPointCollection spTemp = e.StylusDevice.GetStylusPoints(MyIP);
        tempStroke.StylusPoints.Add(spTemp);

        tempStroke.DrawingAttributes.Color = Colors.Red;
        tempStroke.DrawingAttributes.OutlineColor = Colors.Black;

        tempStroke.DrawingAttributes.Width = BrushSize.Value;
        tempStroke.DrawingAttributes.Height = BrushSize.Value;

        MyIP.Strokes.Add(tempStroke);

感谢任何帮助

简单代码

【问题讨论】:

    标签: c# silverlight silverlight-4.0 opacity stroke


    【解决方案1】:

    设置颜色的 alpha 值。例如对于 +-0.5 的不透明度和红色:

    tempStroke.DrawingAttributes.Color = Colors.FromArgb(125,255,0,0);
    

    【讨论】:

      【解决方案2】:

      我认为您必须在颜色上设置 Alpha。 例如:

      //the first 00 would be your alpha channel, then red, then green, then blue
      tempStroke.DrawingAttributes.Color = Colors.FromArgb(0x00,0xFF,0x00,0x00);
      

      【讨论】:

        【解决方案3】:

        您可以将 Color.A 属性设置为 0 到 255 之间的值,或者将 Color.ScA 属性设置为 0 到 1 之间的十进制值。这两个属性保持同步,因此如果您更改其中一个,预计其他更新为等效值。

        http://msdn.microsoft.com/en-us/library/system.windows.media.color.aspx

        【讨论】:

          猜你喜欢
          • 2018-05-18
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-03-23
          • 1970-01-01
          • 2013-12-27
          • 2013-10-06
          相关资源
          最近更新 更多