我们可以在Windows phone 8中擦除透明度吗

本文关键字:擦除 透明度 phone Windows 我们 | 更新日期: 2023-09-27 18:20:34

实际上,我想把图像擦除到透明。就像我在页面背景上有一张图片,在上面有另一张图片。现在我想,如果我用手指擦除上面的图像,那么下面的图像应该出现,简单地说,图像将变得透明。我正在做这样的事情,但它不符合我的要求。欢迎您的建议:)

private void Canvas_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
{
    currentPoint = e.GetPosition(this.canvas);
    //Initialize line according to currentpoint position.
    Line line = new Line() 
                { 
                    X1 = currentPoint.X, 
                    Y1 = currentPoint.Y, 
                    X2 = oldPoint.X, 
                    Y2 =oldPoint.Y 
                };          

    line.StrokeDashCap = PenLineCap.Round;
    line.StrokeEndLineCap = PenLineCap.Round;
    line.StrokeLineJoin = PenLineJoin.Round;
    line.StrokeThickness = 20;
    line.Stroke = new SolidColorBrush(Colors.Black) ;
    ////////////////////////////////
    //Set color & thickness of line. 
    //Line add in canvas children to draw image & assign oldpoint.
    this.canvas.Children.Add(line);
    oldPoint = currentPoint;
}

我们可以在Windows phone 8中擦除透明度吗

你可以用三种不同的方法来实现:

  1. 使用不透明覆盖和UIElement.Clip属性。但是你需要处理Geometry。我担心这将是非常CPU的成本。

  2. 使用WriteableBitmap并改变图像的alpha通道。您可以使用WriteableBitmapEx来完成此操作。

  3. 使用不透明覆盖和UIElement.OpacityMask属性。我认为这是实现这一点的最佳方式,因为您不局限于使用位图(这样您就可以将任何XAML控件放置在覆盖下面),就像第二种方式一样。