• windows phone 多触控画图并保存到 手机图片库 GIS


    http://code.msdn.microsoft.com/CSWP7MultiTouchDrawing-4513213a 原文

    效果图

    image

    算法分析:

    按下鼠标的时候 把这个点加入点的集合,当鼠标移动的时候,把加入的点集 画线

    无论是移动鼠标还是按下鼠标都会触发

      Touch.FrameReported += new TouchFrameEventHandler(Touch_FrameReported);事件

    没触发一次事件 就会捕获到一个点集TouchPointCollection,

       TouchPointCollection pointCollection = e.GetTouchPoints(drawCanvas);

    把这些点集的xy 保存到两个数组

    使用TouchAction 枚举 来判读鼠标的动作up down  move

    void Touch_FrameReported(object sender, TouchFrameEventArgs e)
          {
              int pointsNumber = e.GetTouchPoints(drawCanvas).Count;
              TouchPointCollection pointCollection = e.GetTouchPoints(drawCanvas);

              for (int i = 0; i < pointsNumber; i++)
              {
                  if (pointCollection[i].Action == TouchAction.Down)
                  {
                    
                      preXArray[i] = pointCollection[i].Position.X;
                      preYArray[i] = pointCollection[i].Position.Y;
                  }
                  if (pointCollection[i].Action == TouchAction.Move)
                  {
                      Line line = new Line();
                     
                      line.X1 = preXArray[i];
                      line.Y1 = preYArray[i];
                      line.X2 = pointCollection[i].Position.X;
                      line.Y2 = pointCollection[i].Position.Y;

                      line.Stroke = new SolidColorBrush(Colors.Black);
                      line.Fill = new SolidColorBrush(Colors.Black);
                      drawCanvas.Children.Add(line);

                      preXArray[i] = pointCollection[i].Position.X;
                      preYArray[i] = pointCollection[i].Position.Y;
                  }
              }
          }

    保存到媒体库:

    private void Save_Click(object sender, RoutedEventArgs e)
           {
               MediaLibrary library = new MediaLibrary();//XNA的库 
               WriteableBitmap bitMap = new WriteableBitmap(drawCanvas, null);
               MemoryStream ms = new MemoryStream();
               Extensions.SaveJpeg(bitMap, ms, bitMap.PixelWidth,
                                   bitMap.PixelHeight, 0, 100);//SYYTEM.MEDIA
               ms.Seek(0, SeekOrigin.Begin);
               library.SavePicture(string.Format("Images\\{0}.jpg",
                                                  Guid.NewGuid()), ms);
           }

  • 相关阅读:
    如果获取 上传域的文件名
    更改织梦后台广告
    html5 让IE6,7支持HTML5语义化标签的文件
    如何获取选中的复选框
    手机下的ev.pageX无效
    Ajax
    列出远程git的全部分支
    扫描局域网中Gogs服务器(ruby)
    Xcode删除无用的Symbols信息
    Docker
  • 原文地址:https://www.cnblogs.com/gisbeginner/p/2539953.html
Copyright © 2020-2023  润新知