2014-09-04 101 views
0

其實我想知道要將圖像抹去透明度。就像我在頁面背景上有一個圖像和上面的另一個圖像。現在我想要的是,如果我用手指抹去上面的圖像,那麼下面的圖像應該會出現,簡單的說就是說圖像會變得透明。我正在做這樣的事情,但它不符合我的要求。 您的建議是歡迎:)我們可以在Windows Phone 8中擦除透明嗎?

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; 
} 
+1

聲音有點像重複這個... http://stackoverflow.com/questions/17073357/erase-to-transparency – walther 2014-09-04 10:19:54

+0

@walther不,它不是。這是XAML,而不是GDI。 – 2014-09-04 10:57:01

回答

0

您可以用3周不同的方式做到這一點:

  1. 使用不透明的覆蓋和UIElement.Clip財產。但你需要處理Geometry。我擔心這將會是非常高的CPU成本。使用WriteableBitmap並更改圖像的Alpha通道。你可以使用WriteableBitmapEx

  2. 使用不透明覆蓋圖和UIElement.OpacityMask屬性。我認爲這是實現這一點的最佳方式,因爲您不限於使用位圖(因此您可以將任何XAML控件放置在覆蓋圖下方),如同第二種方式。

+0

Thankx Eldar !!我很感謝你:)你能解釋一下嗎,我是新手機開發.. – 2014-09-04 11:40:43

相關問題