• 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();
                }
            }
  • 相关阅读:
    设计模式-解释器模式
    安卓运行环境(四)
    安卓创建应用窗口(三)
    微型 ORM 的第二篇 DapperLambda性能测试[Dapper比较篇]
    微型 ORM 的第一篇 DapperLambda发布
    visual studio 2013 使用IIS Express附加调试MVC5
    数据库常用查询语句写法(优化)
    Windows Server 2008通过计划任务定时执行bat文件
    第一章 Memcached安装
    第四章 LINQ to SQL基本用法
  • 原文地址:https://www.cnblogs.com/liuxinls/p/2880024.html
Copyright © 2020-2023  润新知