zoukankan      html  css  js  c++  java
  • C#实现放大镜

    winform实现一个跟随鼠标移动放大功能

    实现步骤:

    1、创建一个Form1,一个计时器timer1和一个图片显示控件pictureBox1

    2、核心代码

    复制代码
              int magnification = 2;//倍率,调节放大倍数,可由TrackBar控制调节    
              int mx;                 //鼠标x坐标
              int my;                 //鼠标y坐标
              const int imgWidth = 500;//放大后图片的宽度
              const int imgHeight = 400;//放大后图片的高度
      
              //对定时器添加Tick事件,并设置Enabled为True
              private void timer1_Tick(object sender, EventArgs e)
              {            
                 mx = Control.MousePosition.X;
                 my = Control.MousePosition.Y;
            //对图像进行放大显示         
                 Bitmap bt = new Bitmap(imgWidth / magnification, imgHeight / magnification);
                 Graphics g = Graphics.FromImage(bt);
                 g.CopyFromScreen(
    new Point(Cursor.Position.X - imgWidth / (2*magnification),
    Cursor.Position.Y - imgHeight / (2*magnification)),
    new Point(0, 0),
    new Size(imgWidth / magnification, imgHeight / magnification)); IntPtr dc1 = g.GetHdc(); g.ReleaseHdc(dc1); pictureBox1.Image = (Image)bt; }
    复制代码
     
  • 相关阅读:
    springmvc
    POJ 3683 Priest John's Busiest Day
    POJ 3678 Katu Puzzle
    HDU 1815 Building roads
    CDOJ UESTC 1220 The Battle of Guandu
    HDU 3715 Go Deeper
    HDU 3622 Bomb Game
    POJ 3207 Ikki's Story IV
    POJ 3648 Wedding
    HDU 1814 Peaceful Commission
  • 原文地址:https://www.cnblogs.com/bruce1992/p/14932919.html
Copyright © 2011-2022 走看看