Control Study -> 当鼠标在图片上移动时,放大图像区域

2005年10月07日 20:37:00

(一).说明

将鼠标指向一幅图片的一块区域,此区域会放大显示,变清晰.
用类: Graphics 实现.

(二).图片示例

(三).代码

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Drawing2D;

namespace 放大图像区域
{
/// >summary<
/// Form1 的摘要说明。
/// >/summary<
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.PictureBox pictureBox1;
/// >summary<
/// 必需的设计器变量。
/// >/summary<
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 调用后添加任何构造函数代码
//
}

/// >summary<
/// 清理所有正在使用的资源。
/// >/summary<
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗体设计器生成的代码
/// >summary<
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// >/summary<
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

/// >summary<
/// 应用程序的主入口点。
/// >/summary<
[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


解释这段代码static void chassis_control_loop(chassis_move_t *chassis_move_control_loop) { fp32 max_vector = 0.0f, vector_rate = 0.0f; fp32 temp = 0.0f; fp32 wheel_speed[4] = {0.0f, 0.0f, 0.0f, 0.0f}; uint8_t i = 0; float position_error, speed_error; float position_output, speed_output; float current_position, current_speed; float target_position, target_speed; chassis_move_control_loop->vx_set=vx_set; chassis_move_control_loop->vy_set=vy_set; chassis_move_control_loop->wz_set=angle_set; chassis_vector_to_mecanum_wheel_speed(chassis_move_control_loop->vx_set, chassis_move_control_loop->vy_set, chassis_move_control_loop->wz_set, wheel_speed); if (chassis_move_control_loop->chassis_mode == CHASSIS_VECTOR_RAW) { for (i = 0; i < 4; i++) { chassis_move_control_loop->motor_chassis[i].give_current = (int16_t)(wheel_speed[i]); } } for (i = 0; i < 4; i++) { chassis_move_control_loop->motor_chassis[i].speed_set = wheel_speed[i]; temp = fabs(chassis_move_control_loop->motor_chassis[i].speed_set); if (max_vector < temp) { max_vector = temp; } } if (max_vector > MAX_WHEEL_SPEED) { vector_rate = MAX_WHEEL_SPEED / max_vector; for (i = 0; i < 4; i++) { chassis_move_control_loop->motor_chassis[i].speed_set *= vector_rate; } } for (i = 0; i < 4; i++) { PID_Calc(&chassis_move_control_loop->motor_speed_pid[i], chassis_move_control_loop->motor_chassis[i].speed, chassis_move_control_loop->motor_chassis[i].speed_set); } for (i = 0; i < 4; i++) { chassis_move_control_loop->motor_chassis[i].give_current = (int16_t)(chassis_move_control_loop->motor_speed_pid[i].out); } }
03-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值