winfrom图片放大器
废话不多说,直接上图看效果,左上角是原图片大小,右边是局部放大的效果
主要代码贴在下面,picBox是原图控件名,picBox_Show是放大控件名
private void picBox_Paint(object sender, PaintEventArgs e)
{
if (isMove == true)
{
Graphics g = e.Graphics;
/*画长方形*/
int _x = movedPoint_X - rect_W / 2;
int _y = movedPoint_Y - rect_H / 2;
_x = _x < 0 ? 0 : _x;
_y = _y < 0 ? 0 : _y;
_x = _x >= picBox.Width - rect_W ? picBox.Width - rect_W - 3 : _x; //减3px的目的就是为了让长方形的边框不会刚好被picBox的边框挡住了
_y = _y >= picBox.Height - rect_H ? picBox.Height - rect_H - 3 : _y;
Rectangle rect = new Rectangle(_x, _y, rect_W, rect_H);
g.DrawRectangle(pen, rect);
// g.FillRectangle(brush, rect);
///*填充网格*/
int x1, x2, y1, y2;
x1 = x2 = _x;
y1 = y2 = _y;
x2 += rect_W;
for (int i = 1; i < rowGridCount; i++)
{
y1 += gridSize;
y2 += gridSize;
g.DrawLine(pen, x1, y1, x2, y2);
}
x1 = x2 = _x;
y1 = y2 = _y;
y2 += rect_H;
for (int j = 1; j < columnGridCount; j++)
{
x1 += gridSize;
x2 += gridSize;
g.DrawLine(pen, x1, y1, x2, y2);
}
/*裁剪图片*/
if (picBox_Show.Image != null)
{
picBox_Show.Image.Dispose();
}
Bitmap bmp = (Bitmap)picBox.Image;
//缩放比例
double rate_W = Convert.ToDouble(bmp.Width) / picBox.Width;
double rate_H = Convert.ToDouble(bmp.Height) / picBox.Height;
Bitmap bmp2 = bmp.Clone(new Rectangle(Convert.ToInt32(rate_W * _x), Convert.ToInt32(rate_H * _y), Convert.ToInt32(rate_W * rect_W), Convert.ToInt32(rate_H * rect_H)), picBox.Image.PixelFormat);
picBox_Show.Image = bmp2;
picBox_Show.SizeMode = PictureBoxSizeMode.Zoom;
picBox_Show.Visible = true;
isMove = false;
}
}
//Paint事件中处理逻辑:当鼠标移动在图片的某个位置时,我们需要绘个长方形区域,同时显示局部放大图片(picBox_Show)。当执行picBox.Refresh()方法时将触发该事件。
private void picBox_MouseMove(object sender, MouseEventArgs e)
{
picBox.Focus(); //否则滚轮事件无效
isMove = true;
movedPoint_X = e.X;
movedPoint_Y = e.Y;
picBox.Refresh();
}
//鼠标移开后,局部显示图片(picBox_Show)隐藏,picBox绘制的长方形也要去掉,最简单的就是调用Refresh()方法了。
void picBox_Show_MouseWheel(object sender, MouseEventArgs e)
{
double scale = 1;
if (picBox_Show.Height > 0)
{
scale = (double)picBox_Show.Width / (double)picBox_Show.Height;
}
picBox_Show.Width += (int)(e.Delta * scale);
picBox_Show.Height += e.Delta;
}
bool isMove = false;
//鼠标移动后点的坐标
int movedPoint_X, movedPoint_Y;
//画笔颜色
Pen pen = new Pen(Color.FromArgb(91, 98, 114));
HatchBrush brush = new HatchBrush(HatchStyle.Cross, Color.FromArgb(91, 98, 114), Color.Empty); //使用阴影画笔画网格
//选取区域的大小
const int rect_W = 80;
const int rect_H = 60;
//网格边长:5px 一格
const int gridSize = 2;
//网格的行、列数
int rowGridCount = rect_H / gridSize;
int columnGridCount = rect_W / gridSize;
private void picBox_MouseLeave(object sender, EventArgs e)
{
picBox_Show.Visible = false;
picBox.Refresh();
picBox_Show.Width = 400;
picBox_Show.Height = 300;
}
winfrom图片放大器的更多相关文章
- 写了一个兼容IE9的图片放大器(基于vue)
photoloupe 图片放大器 第一次写vue插件,本人比较喜欢用简单易懂的写法,不喜勿喷. 本插件支持IE9及以上版本,已经过验证. 本插件可根据需要设置放大倍数,最小支持1倍,支持小数 下载地址 ...
- jquery插件——图片放大器
用到了JQzoom插件,可以使图片实现放大效果
- jquery图片放大器插件
将鼠标移动到一张图片上来的时候,放大该图片的某些细节. <html> <head> <script src="../js/jquery-1.6.js" ...
- winfrom 图片等比例压缩
效果图: 核心代码: /// <summary> /// 等比例缩放图片 /// </summary> /// <param name="bitmap" ...
- js 实现的页面图片放大器以及 event中的诸多 x
背景: 淘宝.天猫等电商网站浏览图片时可以查看大图的功能: 思路: 思路很简单,两张图片,一张较小渲染在页面上,一张较大是细节图,随鼠标事件调整它的 left & top; 需要的知识点: o ...
- javascript实现 京东淘宝等商城的商品图片大图预览功能(图片放大器)
在京东和淘宝等购买东西的时候,我们会经常预览左侧商品展示图片,把鼠标放到原图,右侧就会有个大图显示出细节.本文将带领大家写一个这样简单的功能! 一.实现原理 当鼠标移入某一图片内部时,图片上部会出 ...
- JS-商品图片放大器
//给mask添加事件,让其随着鼠标移动 superMask.onmousemove=function(){ var left=event.offsetX-175/2; left=left>0? ...
- JS - 图片放大器
下载地址:http://www.lanrentuku.com/js/tupian-1170.html
- winfrom 图片裁剪 圆形头像
效果 核心代码 public Region DrawingCircle(Rectangle r) { GraphicsPath gp = new GraphicsPath(); gp.AddEllip ...
随机推荐
- vue中$ref的基本用法
1.使用在一般的标签上 <div id="app"> <input ref="count" type="text" v-m ...
- solr搜索配置权重
配置权重 <requestHandler name="/browse" class="solr.SearchHandler" default=" ...
- system v 共享内存
#include <stdio.h> #include <string.h> #include <errno.h> #include <unistd.h> ...
- 如何上传Packages到PyPI并批量抓取
1.如何上传包到PyPI ? 更新中... 2.批量抓取simple网站第三方模块 https://pypi.python.org/simple/ 3. 第三方模块的安装和使用 python set ...
- java中HashMap的基本方法使用
遍历,添加词,等等 package test; import java.util.HashMap; import java.util.Iterator; import java.util.ArrayL ...
- setInterval与setTimeout 的区别
setInterval在执行完一次代码之后,经过了那个固定的时间间隔,它还会自动重复执行代码,而setTimeout只执行一次那段代码 用法: setInterval("alert( ...
- HQL和SQL查询
转自http://blog.csdn.net/aaa1117a8w5s6d/article/details/7757097 HQL和SQL的区别 标签: sqlhibernatejavasessio ...
- codeforces题目合集(持续更新中)
CF280CCF280CCF280C 期望dp CF364DCF364DCF364D 随机化算法 CF438DCF438DCF438D 线段树 CF948CCF948CCF948C 堆 CF961EC ...
- ajax from 提交
$.ajax({ cache: true, type: "POST", url:aj ...
- math.net 拟合
参考:http://blog.csdn.net/ztmsimon/article/details/50524392 在论坛中总看到有人在说Math.NET Iridium,查了一下,现在被整合到Mat ...