我有一个透明的画布,可以在其上用鼠标绘制任意多段线。 大部分线条都是半透明的。清除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