zoukankan      html  css  js  c++  java
  • 页面手势监控(放大,缩小 平移)

    首先  Xaml定义一个Image  实现图片的放大缩小(也可针对页面):

    <Image x:Name="_image"  RenderTransformOrigin="0.5,0.5">  
     <Image.RenderTransform> 
    <CompositeTransform x:Name="transform"/>
     </Image.RenderTransform> 
     <toolkit:GestureService.GestureListener>
    <toolkit:GestureListener  Tap="OnTap" Hold="OnHold" 
     DragStarted="OnDragStarted" DragDelta="OnDragDelta" 
    DragCompleted="OnDragCompleted" Flick="OnFlick"  
     PinchStarted="OnPinchStarted" PinchDelta="OnPinchDelta" 
    PinchCompleted="OnPinchCompleted"/>  
    </toolkit:GestureService.GestureListener>
     </Image>

    在CS里面就要针对该页面写事件:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.IO;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using Microsoft.Phone.Controls;
    using Microsoft.Xna.Framework.Media;
    namespace Demo
    {
        public partial class MainPage : PhoneApplicationPage    
    {
            //SolidColorBrush greenBrush = new SolidColorBrush(Colors.Green);        
    //SolidColorBrush redBrush = new SolidColorBrush(Colors.Red);        
    //SolidColorBrush normalBrush;        
    double initialAngle;        
    double initialScale;        
    Uri _imageURI;        
    BitmapImage _bitMapImage = new BitmapImage();        
    public MainPage()        
    {            
           InitializeComponent();        
    }        
    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
            {
                _imageURI = new Uri("http://photo.fanfou.com/n0/02/5y/3p_215854.jpg");                        
               _bitMapImage.DownloadProgress += new EventHandler<DownloadProgressEventArgs>(bitMapImage_DownloadProgress);
                _bitMapImage.UriSource = _imageURI;
               _image.Source = _bitMapImage;            
    _progressBar.Visibility = System.Windows.Visibility.Visible;
                _progressBar.IsIndeterminate = true;                        
    base.OnNavigatedTo(e);        }        
    void bitMapImage_DownloadProgress(object sender, DownloadProgressEventArgs e)        
    {            
    if (e.Progress == 100)            
    {                               
    _progressBar.Visibility = System.Windows.Visibility.Collapsed;
                    _progressBar.IsIndeterminate = false;            
    }            //throw new NotImplementedException();        
    }        private void OnTap(object sender, Microsoft.Phone.Controls.GestureEventArgs e)        
    {            transform.TranslateX = transform.TranslateY = 0;        
    }        private void OnDoubleTap(object sender, Microsoft.Phone.Controls.GestureEventArgs e)        
    {            transform.ScaleX = transform.ScaleY = 0;
            }        private void OnHold(object sender, Microsoft.Phone.Controls.GestureEventArgs e)        
    {            transform.TranslateX = transform.TranslateY = 0;            
    transform.ScaleX = transform.ScaleY = 0;            
    transform.Rotation = 0;        
    }        private void OnDragStarted(object sender, DragStartedGestureEventArgs e)        
    {            
    //border.Background = greenBrush;       
     }      
      private void OnDragDelta(object sender, DragDeltaGestureEventArgs e)   
         {      
          transform.TranslateX += e.HorizontalChange;    
            transform.TranslateY += e.VerticalChange;     
       }        private void OnDragCompleted(object sender, DragCompletedGestureEventArgs e)   
         {         
       //border.Background = normalBrush;    
        }    
        private void OnPinchStarted(object sender, PinchStartedGestureEventArgs e)  
          {         
       //border.Background = redBrush;    
            initialAngle = transform.Rotation;    
            initialScale = transform.ScaleX;   
         }        private void OnPinchDelta(object sender, PinchGestureEventArgs e)   
         {                     
      transform.Rotation = initialAngle + e.TotalAngleDelta;  
              transform.ScaleX = transform.ScaleY = initialScale * e.DistanceRatio;   
         }        private void OnPinchCompleted(object sender, PinchGestureEventArgs e)  
         {            // _image.Background = normalBrush;     
       }        private void OnFlick(object sender, FlickGestureEventArgs e)    
        {        
        //flickData.Text = string.Format("{0} Flick: Angle {1} Velocity {2},{3}",   
             //    e.Direction, Math.Round(e.Angle), e.HorizontalVelocity, e.VerticalVelocity);       
     }        private void ApplicationBarIconButton_Click(object sender, EventArgs e)  
          {   
             MemoryStream fileStream = new MemoryStream();     
           try          
      {              
      MediaLibrary library = new MediaLibrary();  
                  string lName = DateTime.Now.ToString("yyyyMMddhhmmss") + ".jpg";   
                 WriteableBitmap CaptureImage = new WriteableBitmap(_bitMapImage);     
               // 将WriteableBitmap转换为JPEG流编码,并储存到独立存储里.     
               Extensions.SaveJpeg(CaptureImage, fileStream, CaptureImage.PixelWidth, CaptureImage.PixelHeight, 0, 100); 
                   fileStream.Seek(0, SeekOrigin.Begin);    
                fileStream.Seek(0, SeekOrigin.Current);    
                //把图片加在WP7 手机的媒体库.              
      Picture pic = library.SavePicture(lName, fileStream);    
                fileStream.Close();          
          MessageBox.Show("保存成功!", string.Empty, MessageBoxButton.OK);          
      }       
         catch         
       {           
         MessageBox.Show("保存失败", string.Empty, MessageBoxButton.OK);          
      }          
      finally       
         {      
              fileStream.Close();  
              }    
        }  
      }
    }
  • 相关阅读:
    CVPR2020论文解读:3D Object Detection三维目标检测
    CVPR2020论文介绍: 3D 目标检测高效算法
    自动驾驶感知系统盘点
    CVPR2020论文解析:实例分割算法
    HttpContext
    c# ExecuteScalar()
    C#中DBNull.Value和Null的用法和区别
    Guid
    CommandType.Text
    数据可视化基础专题(三):Pandas基础(二) csv导入与导出
  • 原文地址:https://www.cnblogs.com/zhibin/p/2553291.html
Copyright © 2011-2022 走看看