[英]Can we do erase to transparency in Windows phone 8?
Actually i am wondering to erase an image to transparency. 实际上,我想将图像擦除为透明。 like i have an image on page background and another image above that.
就像我在页面背景上有一张图片,在上面有另一张图片。 Now i want that if i erase above image by finger then lower image should be appear, simply means to say image will become transparent.i'm doing something like this but its not meet my requirements.
现在我想如果我用手指擦除上面的图像,那么应该出现下面的图像,只是意味着说图像将变得透明。我正在做这样的事情,但它不符合我的要求。 Your suggestions are Welcome :)
欢迎您提出建议:)
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;
}
You can do it with 3 different ways: 您可以通过3种不同的方式来做到这一点:
Using opaque overlay and UIElement.Clip
property. 使用不透明的叠加层和
UIElement.Clip
属性。 But you need to deal with Geometry
. 但是您需要处理
Geometry
。 And I'm afraid it will be very CPU cost. 而且恐怕这会占用很大的CPU成本。
Using WriteableBitmap
and changing an alpha channel of image. 使用
WriteableBitmap
并更改图像的Alpha通道。 You can do it using WriteableBitmapEx
. 您可以使用
WriteableBitmapEx
做到这一点。
Using opaque overlay and UIElement.OpacityMask
property. 使用不透明的叠加层和
UIElement.OpacityMask
属性。 I think it's the best way to accomplish that, as you're not limited to use bitmap (so you can place any XAML control below overlay) as in the second way. 我认为这是实现此目标的最佳方法,因为不像第二种方法那样使用位图(因此您可以将任何XAML控件放置在overlay下)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.