WPF的Inkcanvas中添加图片选中的问题。

weixin_38087237 2016-06-19 11:29:08
我在InkCanvas想作为stroke添加图片,以便和墨迹一起处理。使用inkcanvas的select模式时。点击图片大部分区域不能选中,只有点击边框和从右上角到左下角一条斜线区域可以选中。谁能帮我了解下是哪里出了问题。
private void picbtn1_Click(object sender, RoutedEventArgs e)
{
StylusPointCollection pts = new StylusPointCollection();
pts.Add(new StylusPoint(100, 100)); // LeftTopPoint
pts.Add(new StylusPoint(200, 100));
pts.Add(new StylusPoint(100, 200));
pts.Add(new StylusPoint(200, 200));
Stroke s = new CustomStroke1(pts);
ink.Strokes.Add(s);
}


#region 自定义画图片1
public class CustomStroke1 : Stroke
{
private StylusPointCollection s;
public CustomStroke1(StylusPointCollection stylusPoints) : base(stylusPoints)
{
this.s = stylusPoints;
}

//public bool IsSelected
//{
// //get
// //{
// // PropertyInfo property = typeof(Stroke).GetProperty("IsSelected",
// // System.Reflection.BindingFlags.Instance |
// // System.Reflection.BindingFlags.GetProperty |
// // System.Reflection.BindingFlags.NonPublic);
// // return (bool)property.GetValue(this, null);
// //}
//}




protected override void DrawCore(DrawingContext drawingContext, DrawingAttributes drawingAttributes)
{
ImageSource imageSource = new BitmapImage(new Uri("pack://application:,,,/0.bmp"));
System.Windows.Point topLeft = new System.Windows.Point(StylusPoints[0].X, StylusPoints[0].Y);//100, 100
System.Windows.Point topRight = new System.Windows.Point(StylusPoints[1].X, StylusPoints[1].Y);//200, 100
System.Windows.Point centerLeft = new System.Windows.Point(StylusPoints[2].X, StylusPoints[2].Y);//100, 200
System.Windows.Point centerRight = new System.Windows.Point(StylusPoints[3].X, StylusPoints[3].Y);//200, 200
PathGeometry pathGeomery = new PathGeometry();
PathSegmentCollection pathCollection = new PathSegmentCollection();
pathCollection.Add(new LineSegment(topLeft, true));
pathCollection.Add(new LineSegment(topRight, true));
pathCollection.Add(new LineSegment(centerRight, true));
pathCollection.Add(new LineSegment(centerLeft, true));
pathCollection.Add(new LineSegment(topLeft, true));
PathFigure pathFigure = new PathFigure();
pathFigure.IsClosed = true;
pathFigure.IsFilled = true;


pathFigure.StartPoint = topLeft;

pathFigure.Segments = pathCollection;
//图片刷
ImageBrush myimageBrush = new ImageBrush();
myimageBrush.ImageSource = imageSource;
PathFigureCollection pathFigureCollection = new PathFigureCollection();
pathFigureCollection.Add(pathFigure);
pathGeomery.Figures = pathFigureCollection;
drawingContext.DrawGeometry(myimageBrush, new System.Windows.Media.Pen(System.Windows.Media.Brushes.Blue, 2), pathGeomery);
this.s = null;

}
}

#endregion


...全文
51 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复

476

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧