技术开发 频道

Windows Phone 7 学习之画图

  【IT168 技术】在Android 我们需要在屏幕画图,或扩展SurfaceView 或扩展父类View 在OnDraw()里面使用画板和调色笔画画。而在微软的强大封装下,这种画图的试成为了控件的可能,微软将众多日常必要的画图都以控件展示,开发人员则无须过多学习使用Paint 、使用Canvas 等画图知识就能轻松在WP7 手机上画各种图,不过这种灵活性是否会降低呢?这个姑且不深究。

  今天学习的WP7 画图控件有以下几种:

  InkPresenter 可否单纯理解为画图面板?

  Path 路径

  Ellipse 圆形或椭圆形

  Rectangle 矩形,方块矩形或圆角矩形

  Line 直线

  Polygon 封闭多边形

  Polyline 开放多边形

  1.InkPresenter 实现方式:

  为其添加三个事件监听,实现其按下到离开的画图路径:

  < InkPresenter Background="White" LostMouseCapture="inkPresenter1_LostMouseCapture" MouseLeftButtonDown="inkPresenter1_MouseLeftButtonDown" MouseMove="inkPresenter1_MouseMove" Height="471" HorizontalAlignment="Left" Margin="24,25,0,0" Name="inkPresenter1" VerticalAlignment="Top" Width="411" />

  监听内部实现代码都有添加注释,代码如下:

  public partial class InkPresenterPage : PhoneApplicationPage

  {

  //从手指落下到抬起就称为一个Stroke

  Stroke mStroke;

  public InkPresenterPage()

  {

  InitializeComponent();

  }

  private void inkPresenter1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)

  {

  //捕捉按下动作

  inkPresenter1.CaptureMouse();

  //一个按下触发的动作为stroke ,对于这些stroke 的点为stylusPoint,故要创建一个集合的点

  StylusPointCollection spc = new StylusPointCollection();

  //从inkPresenter 中得到每个stylusPoint 并添加到集合里面

  spc.Add(e.StylusDevice.GetStylusPoints(inkPresenter1));

  //实例化一个stroke到inkPresenter里面

  mStroke = new Stroke();

  //将stroke 添加

  this.inkPresenter1.Strokes.Add(mStroke);

0
相关文章