• 大小: 48KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-05
  • 语言: C#
  • 标签: C#  中键  图像  缩放  平移  

资源简介

有用得着的就下载吧 鼠标中键点下平移图像 中键滚动 根据鼠标位置缩放图像

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ImageScale
{
    public partial class Form1 : Form
    {
        public Form1() {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;
            this.pictureBox1.Borderstyle = Borderstyle.FixedSingle;
            this.pictureBox1.BackColor = Color.DarkGray;
            this.pictureBox1.MouseWheel += new MouseEventHandler(pictureBox1_MouseWheel);
        }

        Bitmap m_bmp;               //画布中的图像
        Point m_ptCanvas;           //画布原点在设备上的坐标
        Point m_ptCanvasBuf;        //重置画布坐标计算时用的临时变量
        Point m_ptBmp;              //图像位于画布坐标系中的坐标
        float m_nScale = 1.0F;      //缩放比例

        Point m_ptMouseDown;        //鼠标点下是在设备坐标上的坐标

        string m_strMousePt;        //鼠标当前位置对应的坐标

        private void Form1_Load(object sender EventArgs e) {
            m_bmp = GetScreen();
            //初始化 坐标
            m_ptCanvas = new Point(pictureBox1.Width / 2 pictureBox1.Height / 2);
            m_ptBmp = new Point(-(m_bmp.Width / 2) -(m_bmp.Height / 2));
        }
        //获取屏幕图像
        public Bitmap GetScreen() {
            Bitmap bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width
                Screen.PrimaryScreen.Bounds.Height);
            using (Graphics g = Graphics.FromImage(bmp)) {
                g.CopyFromScreen(0 0 0 0 bmp.Size);
            }
            return bmp;
        }
        //重绘图像
        private void pictureBox1_Paint(object sender PaintEventArgs e) {
            Graphics g = e.Graphics;
            g.TranslateTransform(m_ptCanvas.X m_ptCanvas.Y);       //设置坐标偏移
            g.ScaleTransform(m_nScale m_nScale);                   //设置缩放比
            g.DrawImage(m_bmp m_ptBmp);                            //绘制图像

            g.ResetTransform();                                     //重置坐标系
            Pen p = new Pen(Color.Cyan 3);
            g.DrawLine(p 0 m_ptCanvas.Y pictureBox1.Width m_ptCanvas.Y);
            g.DrawLine(p m_ptCanvas.X 0 m_ptCanvas.X pictureBox1.Height);
            p.Dispose();
            //绘制网格线
            float nIncrement = (50 * m_nScale);             //网格间的间隔 根据比例绘制
            for (float x = m_ptCanvas.X; x > 0; x -= nIncrement)
                g.DrawLine(Pens.Cyan x 0 x pictureBox1.Height);
            for (float x = m_ptCanvas.X; x < pictureBox1.Width; x += nIncrement)
                g.DrawLine(Pens.Cyan x 0 x pictureBox1.Height);
            for (float y = m_ptCanvas.Y; y > 0; y -= nIncrement)
                g.DrawLine(Pens.Cyan 0 y pictureBox1.Width y);
            for (float y = m_ptCanvas.Y; y < pictureBox1.Width; y += nIncrement)
                g.DrawLine(Pens.Cyan 0 y pictureBox1.Width y);
            //计算屏幕左上角 和 右下角 对应画布上的坐标
            Size szTemp =

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2012-10-26 23:42  ImageScale\
     目录           0  2012-10-26 23:43  ImageScale\ImageScale\
     文件         872  2012-10-26 23:42  ImageScale\ImageScale.sln
     文件       17920  2012-10-28 18:51  ImageScale\ImageScale.suo
     目录           0  2012-10-26 23:42  ImageScale\ImageScale\bin\
     目录           0  2012-10-26 23:45  ImageScale\ImageScale\bin\Debug\
     文件       12288  2012-10-29 02:59  ImageScale\ImageScale\bin\Debug\ImageScale.exe
     文件       28160  2012-10-29 02:59  ImageScale\ImageScale\bin\Debug\ImageScale.pdb
     文件       11608  2012-10-29 03:01  ImageScale\ImageScale\bin\Debug\ImageScale.vshost.exe
     文件         490  2010-03-17 22:39  ImageScale\ImageScale\bin\Debug\ImageScale.vshost.exe.manifest
     文件        7623  2012-10-29 02:59  ImageScale\ImageScale\Form1.cs
     文件        2498  2012-10-29 02:15  ImageScale\ImageScale\Form1.Designer.cs
     文件        5817  2012-10-28 17:08  ImageScale\ImageScale\Form1.resx
     文件        3427  2012-10-26 23:45  ImageScale\ImageScale\ImageScale.csproj
     目录           0  2012-10-26 23:42  ImageScale\ImageScale\obj\
     目录           0  2012-10-26 23:42  ImageScale\ImageScale\obj\x86\
     目录           0  2012-10-29 02:59  ImageScale\ImageScale\obj\x86\Debug\
     文件        5422  2012-10-29 02:59  ImageScale\ImageScale\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件        1028  2012-10-29 03:01  ImageScale\ImageScale\obj\x86\Debug\ImageScale.csproj.FileListAbsolute.txt
     文件       12288  2012-10-29 02:59  ImageScale\ImageScale\obj\x86\Debug\ImageScale.exe
     文件         180  2012-10-28 17:08  ImageScale\ImageScale\obj\x86\Debug\ImageScale.Form1.resources
     文件       28160  2012-10-29 02:59  ImageScale\ImageScale\obj\x86\Debug\ImageScale.pdb
     文件         180  2012-10-26 23:45  ImageScale\ImageScale\obj\x86\Debug\ImageScale.Properties.Resources.resources
     文件        3970  2012-10-28 17:08  ImageScale\ImageScale\obj\x86\Debug\ResGen.read.1.tlog
     文件        1324  2012-10-28 17:08  ImageScale\ImageScale\obj\x86\Debug\ResGen.write.1.tlog
     目录           0  2012-10-26 23:42  ImageScale\ImageScale\obj\x86\Debug\TempPE\
     文件         473  2012-10-26 23:42  ImageScale\ImageScale\Program.cs
     目录           0  2012-10-26 23:42  ImageScale\ImageScale\Properties\
     文件        1450  2012-10-26 23:42  ImageScale\ImageScale\Properties\AssemblyInfo.cs
     文件        2765  2012-10-26 23:42  ImageScale\ImageScale\Properties\Resources.Designer.cs
     文件        5612  2012-10-26 23:42  ImageScale\ImageScale\Properties\Resources.resx
............此处省略2个文件信息

评论

共有 条评论