我有一個透明的畫布,可以在其上用鼠標繪製任意多段線。 大部分線條都是半透明的。清除WPF畫布中的像素
現在我需要某種橡皮擦工具,即帶有橡皮刷的多段線,它允許沿着鼠標移動清除像素。
使用不透明的畫布時,我會簡單地使用背景畫筆,但在這種情況下,它是Color.FromArgb(0,0,0,0),並且使用該畫筆無效。
畫布似乎處於某種alpha混合模式,它將我在其上繪製的任何東西與已存在的東西混合,除非將alpha通道設置爲255,在這種情況下,畫布上的任何內容都將被覆蓋。這對我沒有幫助,因爲我只是想清除像素,即使它們完全透明。
任何想法?
下面的代碼的主要部分我使用:
public class WPFWindow : Window
{
private Canvas canvas = new Canvas();
private bool LDown = false;
private Polyline lines;
private PointCollection points;
public WPFWindow()
{
this.AllowsTransparency = true;
this.WindowStyle = WindowStyle.None;
this.Background = new SolidColorBrush(Color.FromArgb(50,0,0,0));
this.Width = 500;
this.Height = 400;
this.Top = this.Left = 0;
canvas.Width = this.Width;
canvas.Height = this.Height;
canvas.Background = new SolidColorBrush(Color.FromArgb(0,0,0,0));
this.Content = canvas;
this.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(WPFWindow_MouseLeftButtonDown);
this.MouseLeftButtonUp += new System.Windows.Input.MouseButtonEventHandler(WPFWindow_MouseLeftButtonUp);
this.MouseMove += new System.Windows.Input.MouseEventHandler(WPFWindow_MouseMove);
}
void WPFWindow_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
{
if(LDown)
{
points.Add(e.GetPosition(null));
}
}
void WPFWindow_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
LDown = false;
}
void WPFWindow_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
LDown = true;
lines = new Polyline();
points = new PointCollection();
lines.Stroke = new SolidColorBrush(Color.FromArgb(128, 180, 80, 80));
lines.StrokeThickness = 20;
lines.Points = points;
points.Add(e.GetPosition(null));
canvas.Children.Add(lines);
}
}
你是如何繪製你的折線?發佈一些代碼(包括目前不工作的東西)會有所幫助。 – 2011-02-03 09:31:49
@Harald:看起來你不小心創建了兩個賬戶。按照[在此給出的說明](http://meta.stackexchange.com/questions/18232/how-can-one-link-merge-combine-associate-two-accounts-users-anonymous-unregiste/73801#73801)讓主持人合併您的帳戶。 – 2011-02-03 10:09:22