版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、图像的局部放大基于winform下的pictBox控件和button控件实现的:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.IO;using System.Threading;namespace 图像的局部放大 public partial class Form1
2、: Form public Form1() InitializeComponent(); Cursor mycur = new Cursor(C:windowscursorscross_l.cur); Bitmap image; private void button1_Click(object sender, EventArgs e) OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = Jpeg File(*.jpg)|*.jpg; if (ofd.ShowDialog()=DialogResult.OK) image = new
3、Bitmap(ofd.FileName); pictureBox1.Image = image; pictureBox1.Width = image.Width; pictureBox1.Height = image.Height; Private void pictureBox1_MouseMove(object sender, MouseEventArgs e) if (image != null) Cursor.Current = mycur; Graphics g = pictureBox1.CreateGraphics(); this.pictureBox1.Refresh();/清
4、楚原来的内容重绘pictureBox的图像 Rectangle soureRec = new Rectangle(e.X-100 , e.Y-100 , 200, 200); /100代表图片放大的区域的尺寸和位置,其中e.x-100,e.y-100代表光标处于需要放大图像区域的中间位置 Rectangle destRec = new Rectangle(e.X-200 , e.Y-200 , 400, 400);/200代表图片放大后的区域的尺寸和位置,其中e.x-200,e.y-200代表光标处于需要放大图像区域的中间位置 g.DrawImage(image, destRec, soure
5、Rec, GraphicsUnit.Pixel); /在指定位置按照指定大小绘制Image图像,则该图像放大了(200/100)倍 else MessageBox.Show(选择需要显示的图片); 另一种参考程序:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace 图像的局部放大
6、01 public partial class Form1 : Form public static int i = 0; private Point m_ptStart = new Point(0, 0); private Point m_ptEnd = new Point(0, 0); private bool m_bMouseDown = false; private float xRate, yRate, realX1, realY1, realX2, realY2; int pLeft = 0; int pTop = 0; public Form1() InitializeCompo
7、nent(); private void Form1_Load(object sender, EventArgs e) xRate = (float)pictureBox1.Image.Width / pictureBox1.Width; yRate = (float)pictureBox1.Image.Height / pictureBox1.Height; SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); / 禁止擦除背景. SetStyle(Contro
8、lStyles.DoubleBuffer, true); /双缓冲 private void pictureBox1_MouseDown(object sender, MouseEventArgs e) if (pictureBox1.HasChildren) for (int i = 0; i pictureBox1.Controls.Count; i+) pictureBox1.Controls.RemoveAt(0); if (e.Button != MouseButtons.Left) return; m_ptEnd = new Point(e.X, e.Y); this.pictur
9、eBox1.Refresh(); realX1 = e.X * xRate; realY1 = e.Y * yRate; if (!m_bMouseDown) m_ptStart = new Point(e.X, e.Y); m_ptEnd = new Point(e.X, e.Y); m_bMouseDown = !m_bMouseDown; private void pictureBox1_Paint(object sender, PaintEventArgs e) if (m_ptEnd.X - m_ptStart.X 0 | m_ptEnd.Y - m_ptStart.Y = 100)
10、 m_ptEnd.X = m_ptStart.X + 100; if (m_ptEnd.Y - m_ptStart.Y = 100) m_ptEnd.Y = m_ptStart.Y + 100; e.Graphics.DrawRectangle(System.Drawing.Pens.Blue, m_ptStart.X, m_ptStart.Y, m_ptEnd.X - m_ptStart.X, m_ptEnd.Y - m_ptStart.Y); private void pictureBox1_MouseUp(object sender, MouseEventArgs e) int eX =
11、 0, eY = 0; if (e.Button != MouseButtons.Left) return; if (e.X - m_ptStart.X = 100) if (e.X = pictureBox1.Width - 1) if (pictureBox1.Width - m_ptStart.X - 1 100) eX = m_ptStart.X + 100; else eX = pictureBox1.Width - 1; else eX = m_ptStart.X + 100; else if (e.X = pictureBox1.Width - 1) eX = pictureBo
12、x1.Width - 1; else eX = e.X; if (e.Y - m_ptStart.Y = 100) if (e.Y = pictureBox1.Height - 1) if (pictureBox1.Height - m_ptStart.Y - 1 100) eX = m_ptStart.Y + 100; else eY = pictureBox1.Height - 1; else eY = m_ptStart.Y + 100; else if (e.Y = pictureBox1.Height - 1) eY = pictureBox1.Height - 1; else eY
13、 = e.Y; if (m_ptStart.X = 0 & m_ptEnd.X = 0 & m_ptStart.Y = 0 & m_ptEnd.Y = 0 & m_ptStart.X = 254 & m_ptEnd.X = 254 & m_ptStart.Y = 163 & m_ptEnd.Y pLeft = e1.X; pTop = e1.Y; ; p.MouseMove += (s2, e2) = GC.Collect(); if (e2.Button.ToString().Equals(Left) if (p.Location.X + e2.X - pLeft = pictureBox1
14、.Width - p.Width) p.Left = pictureBox1.Width - p.Width - 1; else p.Left = p.Location.X + e2.X - pLeft; if (p.Location.Y + e2.Y - pTop = pictureBox1.Height - p.Height) p.Top = pictureBox1.Height - p.Height - 1; else p.Top = p.Location.Y + e2.Y - pTop; Crop(Bitmap)pictureBox1.Image, Convert.ToInt32(p.
15、Location.X * xRate), Convert.ToInt32(p.Location.Y * yRate), Convert.ToInt32(p.Width), Convert.ToInt32(p.Height); ; pictureBox1.Controls.Add(p); private void pictureBox1_MouseMove(object sender, MouseEventArgs e) if (e.Button != MouseButtons.Left) return; m_ptEnd = new Point(e.X, e.Y); this.pictureBox1.Refresh(); private void Crop(Bitmap bitmap, int X, int Y, int width, int height) if (width 0 & height 0) Re
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年顺德市中西医结合医院医护人员招聘笔试题库及答案详解
- 2026年屯昌县中医院医护人员招聘考试模拟试题及答案详解
- 2026年温州市红旗医院医护人员招聘考试模拟试题及答案详解
- 晋城市妇幼保健院招聘笔试真题2025
- 2025年广州市越秀区第二中医医院医护人员招聘笔试题库及答案详解
- 2025年汉中市口腔医院医护人员招聘笔试题库及答案详解
- 2026年化隆县中医院医护人员招聘考试参考题库附答案详解
- 2025年涟水县南禄卫生院医护人员招聘笔试题库及答案详解
- 2025年吉林市徐景信中医肿瘤皮肤病研治所医护人员招聘笔试题库及答案详解
- 2025年阜新矿业集团公司平安医院医护人员招聘笔试题库及答案详解
- 2026年辽宁锦州文旅(集团)有限公司计划招录15人备考题库及完整答案详解一套
- 精细化工生产线项目运营管理方案
- 2026年青岛中考物理考试试题及答案
- 冶金行业班组安全管理制度培训
- 手术室护理患者安全与隐私保护
- 2026广东广州市人力资源和社会保障局系统事业单位招聘事业编制人员166人(第一次)考试备考试题及答案解析
- 2025年贵州省黔南州事业单位遴选笔试真题及参考答案
- 2026年企业并购重组中的人力资源整合
- 2026-2030中国止血药市场应用趋势调研及投资前景展望研究报告
- 中建三局新员工转正考核
- 2026春季学期国家开放大学专科《高等数学基础》一平台在线形考形考任务一试题及答案
评论
0/150
提交评论