zoukankan      html  css  js  c++  java
  • C# 实现图片的放大缩小和平移

    private void DSApictureBox_MouseDown(object sender, MouseEventArgs e)
            {
                if (drawLine)
                {
                    start = new PointF(e.X,e.Y);
                    start = LineAlgorithm.Control2Image(matrix,start);
    
                    if (list1.Count == 0)
                    {
                        addLine1 = true;
                    }
                    else
                    {
                        addLine1 = false;
                    }
                }
                if ((Control.ModifierKeys & Keys.Control) == Keys.Control)
                {
                    if (e.Button == MouseButtons.Left)
                    {
                        isZooming = true;
                    }
                    else
                    {
                        isZooming = false;
                    }
                    if (e.Button == MouseButtons.Right)
                    {
                        isPanning = true;
                    }
                    else
                    {
                        isPanning = false;
                    }
                    startPoint = new System.Drawing.Point(e.X, e.Y);
                    drawLine = false;
                }
            }
     private void DSApictureBox_MouseMove(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Left && drawLine)
                {
                   
                    end = new PointF(e.X,e.Y);
                    end = LineAlgorithm.Control2Image(matrix,end);
                    if (addLine1)
                    {
                        list1.Add(end);
                    }
                    else
                    {
                        list2.Add(end);
                        cursorToolStripMenuItem.Enabled = true;
                       
                    }
                    DSApictureBox.Refresh();
                }
                if (startPoint.HasValue && drawLine == false)
                {
                    int diffX = e.X - startPoint.Value.X;
                    int diffY = e.Y - startPoint.Value.Y;
    
                    //Console.WriteLine(string.Format("DiffX {0} DiffY {1}", diffX, diffY));
    
                    if (isPanning)
                    {
                        PointF p1 = new PointF(startPoint.Value.X, startPoint.Value.Y);
                        PointF p2 = new PointF(e.X, e.Y);
                        Console.WriteLine(string.Format("p1 {0} {1}", p1.X, p1.Y));
                        Console.WriteLine(string.Format("p2 {0} {1}", p2.X, p2.Y));
    
                        matrix.Invert();
                        var pts = new PointF[] { p1, p2 };
                        matrix.TransformPoints(pts);
    
                        Console.WriteLine(string.Format("p1 {0} {1}", pts[0].X, pts[0].Y));
                        Console.WriteLine(string.Format("p2 {0} {1}", pts[1].X, pts[1].Y));
    
                        matrix.Invert();
    
                        matrix.Translate(pts[1].X - pts[0].X, pts[1].Y - pts[0].Y);
                    }
                    if (isZooming)
                    {
                        matrix.Scale((300 + diffX) / 300f, (300 + diffX) / 300f);
                    }
    
                    startPoint = new System.Drawing.Point(e.X, e.Y);
    
                    DSApictureBox.Refresh();
                }
            }
  • 相关阅读:
    对象形式传递
    解决DLNA方案的技术框架
    关于DLNA
    MAC配置Xcode的Cocos2d-x环境
    什么叫做双缓冲?
    Window7 Cocos2d-x配置开发环境
    Windows 8.1 Update 2更新了什么?
    微软发布Windows Phone 8.1 Update 和中文版Cortana“小娜”
    大开眼界 游览Facebook香港办公室
    小米的“假照片”危机
  • 原文地址:https://www.cnblogs.com/liuxinls/p/2880024.html
Copyright © 2011-2022 走看看