c#图片截取DEMO
2012-12-15 10:42
127 查看
截图DEMO
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Drawing.Imaging; namespace 图片截图 { public partial class Form1 : Form { bool isDrag = false; Rectangle theRectangle = new Rectangle(new Point(0, 0), new Size(0, 0)); Point startPoint, oldPoint; private Graphics ig; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { } private void button2_Click(object sender, EventArgs e) { openFileDialog1.Filter = "*.jpg,*.jpeg,*.bmp,*.gif,*.ico,*.png,*.tif,*.wmf|*.jpg;*.jpeg;*.bmp;*.gif;*.ico;*.png;*.tif;*.wmf"; openFileDialog1.ShowDialog(); Image myImage = System.Drawing.Image.FromFile(openFileDialog1.FileName); pictureBox1.Image = myImage; } private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { //如果开始绘制,则开始记录鼠标位置 if ((isDrag = !isDrag) == true) { startPoint = new Point(e.X, e.Y); oldPoint = new Point(e.X, e.Y); } } } private void pictureBox1_MouseUp(object sender, MouseEventArgs e) { isDrag = false; ig = pictureBox1.CreateGraphics(); ig.DrawRectangle(new Pen(Color.Black, 1), startPoint.X, startPoint.Y, e.X - startPoint.X, e.Y - startPoint.Y); theRectangle = new Rectangle(startPoint.X, startPoint.Y, e.X - startPoint.X, e.Y - startPoint.Y); } private void pictureBox1_MouseClick(object sender, MouseEventArgs e) { try { //Graphics graphics = this.CreateGraphics(); Bitmap bitmap = new Bitmap(pictureBox1.Image); Bitmap cloneBitmap = bitmap.Clone(theRectangle, PixelFormat.DontCare); pictureBox2.Image = (Image)cloneBitmap; //graphics.DrawImage(cloneBitmap, e.X, e.Y); Graphics g = pictureBox1.CreateGraphics(); SolidBrush myBrush = new SolidBrush(Color.Transparent); g.FillRectangle(myBrush, theRectangle); } catch { } } } }
相关文章推荐
- jquery图片截取DEMO
- Android中如何截取图片地址的字符串
- 图片相关操作(截取,缩略,翻转。。。。)
- 官方demo修改后的webuploader上传预览图片(兼容IE8) github下载回来的有问题
- javacpp-opencv图像处理之1:实时视频添加文字水印并截取视频图像保存成图片,实现文字水印的字体、位置、大小、粗度、翻转、平滑等操作
- 页面图片切换DEMO
- Android 用模拟器的CameraDevice截取图片
- iOS 通过CGImageRef来进行图片的截取、裁剪
- 阿里云服务器 云对象存储OOS(二) ---图片上传与读取demo
- jQuery实现可以控制图片旋转角度效果(附demo源码下载)
- php图片截取代码说明
- android将给定图片维持宽高比缩放后,截取正中间的正方形部分
- 用ImageLoader缓存,volley网络请求百度api的图片显示在listview(demo)
- 利用jQuery UI 实现图片部份截取
- Linux V4L2 截取图片
- C#放缩、截取、合并图片并生成高质量新图的类
- JS图片延迟加载分析及简单的demo
- 自定义CircleView圆形图片Demo
- 关于对KindEditor官网demo的上传本地图片upload_json.jsp的改进
- 使用jquery jcrop插件进行图片的截取与保存