Control Study -> 当鼠标在图片上移动时,放大图像区域
来源:互联网 发布:java工程师证书 编辑:程序博客网 时间:2024/05/14 01:54
(一).说明
将鼠标指向一幅图片的一块区域,此区域会放大显示,变清晰.
用类: Graphics 实现.
(二).图片示例
(三).代码
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Drawing2D;
namespace 放大图像区域
{
///
/// Form1 的摘要说明。
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.PictureBox pictureBox1;
///
/// 必需的设计器变量。
///
private System.ComponentModel.Container components = null;
private System.Windows.Forms.Button button1;
//private Cursor myCursor;
Cursor myCursor=new Cursor("..//..//MAGNIFY.cur"); //自定义鼠标
Graphics g;
Image myImage;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
///
/// 清理所有正在使用的资源。
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
///
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
///
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.BackColor = System.Drawing.SystemColors.ControlText;
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(24, 16);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(440, 384);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
this.pictureBox1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove);
//
// button1
//
this.button1.Location = new System.Drawing.Point(384, 96);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
this.ClientSize = new System.Drawing.Size(472, 406);
this.Controls.Add(this.button1);
this.Controls.Add(this.pictureBox1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
this.ResumeLayout(false);
}
#endregion
///
/// 应用程序的主入口点。
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void pictureBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
Cursor.Current=myCursor;
Rectangle sourceRectangle=new Rectangle(e.X-10,e.Y-10,20,20); //要放大的区域
//Rectangle destRectangle=new Rectangle(e.X-20,e.Y-20,40,40);
Rectangle destRectangle=new Rectangle(pictureBox1.Width-150,pictureBox1.Height-150,pictureBox1.Width,pictureBox1.Height); //放大的比例
g.DrawImage(myImage,destRectangle,sourceRectangle,GraphicsUnit.Pixel);
}
private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
Cursor.Current=Cursors.Default;
}
private void Form1_Load(object sender, System.EventArgs e)
{
g=this.pictureBox1.CreateGraphics();
myImage=this.pictureBox1.Image;
}
private void button1_Click(object sender, System.EventArgs e)
{
//Graphics g=this.pictureBox1.CreateGraphics();
Graphics g=pictureBox1.CreateGraphics();
g.DrawLine(new Pen(Color.Red,5),20,20,50,50);
}
}
}
(四).示例下载
http://www.cnblogs.com/Files/ChengKing/放大图像区域.rar
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=496680
- Control Study -> 当鼠标在图片上移动时,放大图像区域
- Control Study -> 当鼠标在图片上移动时,放大图像区域
- Control Study -> 当鼠标在图片上移动时,放大图像区域
- 图片在网页上移动
- 鼠标在菜单上移动时显示菜单提示
- 使用鼠标在面板上移动消息
- 顶部图片随滑动上移动和向下放大
- OpenCV图像处理->鼠标移动区域放大
- Control Study -> 实现:用鼠标拖动图片
- Control Study -> 实现:用鼠标拖动图片
- Control Study -> 实现:用鼠标拖动图片
- canvas 图片鼠标区域放大细节
- 当点C在抛物线上移动时,求点P的轨迹方程
- 当鼠标移动到图片上时,跟随鼠标显示放大的图片
- 鼠标在按钮上移动、按下或者弹起时显示按钮功能提示文本
- 鼠标在有颜色的界面上移动时留下一条条白线
- 经纬度随鼠标在地图上移动随时显示
- 经纬度随鼠标在地图上移动随时显示
- Control Study -> 键盘模拟鼠标(实现用键盘操作鼠标光标)(示例代码下载)
- Collection -> 集合的同步执行
- Collection -> 集合的拷贝
- Collection -> 用SortedList实现排序
- Control Study -> 用获取路径方法得到圆形窗体(如将: PictureBox变成圆形)
- Control Study -> 当鼠标在图片上移动时,放大图像区域
- ADO.Net都有哪些从数据库获取数据的方式
- 遍历目录和文件信息
- asp.net生成曲线图的过程
- 用 winmm 播放音乐
- 生成n位不同的验证码
- Collection -> 由IComparer派生的自定义比较器
- 当DataSet中包含主/子表时,Update更新步骤
- 什么是爱情?这就是爱情