【C#】winform 图片局部放大类似淘宝
来源:互联网 发布:东北林业大学 知乎 编辑:程序博客网 时间:2024/04/29 17:03
整体效果:
有两个picturebox控件,name默认没有修改。其中picturebox1的img赋予初始值,picturebox2的visible=false;其余不变,程序比较简单,看以参考下。
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading;using System.Threading.Tasks;using System.Windows.Forms;namespace 局部放大{ public partial class Form1 : Form { Thread thDraw; delegate void myDrawRectangel(); myDrawRectangel mydraw; private Point ptBegin = new Point(); private bool blIsDrawRectangle = false; public Form1() { InitializeComponent(); } private void pictureBox1_Paint(object sender, PaintEventArgs e) { //画矩形 初始值为false否则 一开始就会显示矩形框 if (blIsDrawRectangle) { e.Graphics.DrawRectangle(new Pen(Brushes.Black, 1), ptBegin.X, ptBegin.Y, 50, 50); } } private void Form1_Load(object sender, EventArgs e) { mydraw = new myDrawRectangel(ShowDrawRectangle); thDraw = new Thread(Run); thDraw.Start(); } private void Run() { while (true) { if (pictureBox1.Image != null) { this.BeginInvoke(mydraw); } Thread.Sleep(50); } } private void Form1_FormClosed(object sender, FormClosedEventArgs e) { if (thDraw != null) { thDraw.Abort(); } } private void ShowDrawRectangle() { Rectangle rec = new Rectangle(ptBegin.X * pictureBox1.Image.Size.Width / 460, ptBegin.Y * pictureBox1.Image.Size.Height / 350, 50 * pictureBox1.Image.Size.Width / 460, 50 * pictureBox1.Image.Size.Height / 350); Graphics g = pictureBox2.CreateGraphics(); g.DrawImage(pictureBox1.Image, pictureBox2.ClientRectangle, rec, GraphicsUnit.Pixel); g.Flush(); } private void pictureBox1_MouseLeave(object sender, EventArgs e) { pictureBox2.Visible = false; blIsDrawRectangle = false; pictureBox1.Refresh(); } private void pictureBox1_MouseEnter(object sender, EventArgs e) { pictureBox2.Visible = true; blIsDrawRectangle = true; } private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { if (e.X - 25 <= 0) { ptBegin.X = 0; } else if (pictureBox1.Size.Width - e.X <= 25) { ptBegin.X = pictureBox1.Size.Width - 50; } else { ptBegin.X = e.X - 25; } if (e.Y - 25 <= 0) { ptBegin.Y = 0; } else if (pictureBox1.Size.Height - e.Y <= 25) { ptBegin.Y = pictureBox1.Size.Height - 50; } else { ptBegin.Y = e.Y - 25; } pictureBox1.Refresh(); } }}
源码:
csdn上没法上传
暂时yunfile:http://filemarkets.com/fs/1sblat4ifa4n3xbia6/
0 0
- 【C#】winform 图片局部放大类似淘宝
- Winform图片局部放大效果
- WPF和Winform中picturebox图片局部放大
- js淘宝局部放大效果
- 【淘宝】图片放大 代码
- jqzoom 图片局部放大
- winform 图片放大缩小
- 仿淘宝的放大图片
- 仿淘宝图片放大处理
- 仿淘宝图片划过放大
- 用javascript放大图片局部
- Android 图片局部放大效果
- 实现局部放大图片功能
- C#(winform)实现图片的无损放大缩小【点击鼠标滚动键放大缩小】
- WinForm 鼠标经过图片 放大
- 仿淘宝图片放大预览效果
- 图片的局部放大的效果实现
- 实现图片局部放大_放大镜效果
- require与require_once与include以及include_once的区别
- Cross Apply 和 Outer Apply
- LR:接口性能测试时提示:Code-29723 Error: Failed to deliver a p2p message from parent to child process, reason
- solr定时增量索引
- KMP学习之路【KMP】
- 【C#】winform 图片局部放大类似淘宝
- 制作动态及静态Framework
- HTTP协议 常用 总结
- 深入理解Java内存模型(三)——顺序一致性
- 如何检测您的浏览器是否支持HTML5视频
- 关于24点游戏的编程思路与基本算法
- Codeforce 383C. Propagating tree
- ps 红眼工具 将拍照片时出现的红眼消除
- 深入理解Java内存模型(二)——重排序