剪切图像
图像 剪切
2023-09-14 09:00:20 时间
实现效果:
知识运用:
Bitmap类的Clone方法 //创建Bitmap对象的 某个部分 的副本
public Bitmap Clone (Rectangle rect, PixelFormat format) //由Rectangle结构和指定的PixelFormat枚举定义
Graphics类的FillRectangle方法 //填充Rectangle结构指定的矩形的内部
public void FillRectangle (Brush brush, Rectangle rect)
实现代码:
private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { startPt = new Point(e.X, e.Y); } } private void pictureBox1_MouseUp(object sender, MouseEventArgs e) { ig = pictureBox1.CreateGraphics(); rectangle = new Rectangle(startPt.X, startPt.Y, e.X-startPt.X, e.Y-startPt.Y); ig.DrawRectangle(new Pen(Color.Black, 1), rectangle); } private void Form1_MouseClick(object sender, MouseEventArgs e) { try { Graphics g = this.CreateGraphics(); Bitmap bmp = new Bitmap(pictureBox1.Image); Bitmap cutBmp = bmp.Clone(rectangle,System.Drawing.Imaging.PixelFormat.DontCare); g.DrawImage(cutBmp,e.X,e.Y); SolidBrush myBrush = new SolidBrush(Color.Wheat); ig.FillRectangle(myBrush,rectangle); } catch{} }
相关文章
- opencv 图像resize
- High&NewTech:20190824上海人工智能大会(2019SHAI)暨第二届图像视频处理与人工智能国际会议参会感悟记录(待整理)
- 【MCTV】通过非凸总变异最小化重建凸 MR 脑图像(Matlab代码实现)
- Qt QLabel show 显示图像、填充、缩放
- Python图像处理丨基于K-Means聚类的图像区域分割
- 【OpenCV 例程300篇】40. 图像分段线性灰度变换
- 【OpenCV 例程 300篇】255.OpenCV 实现图像拼接
- 【多模态图像合成与编辑】Multimodal Image Synthesis and Editing:A Survey(综述)
- 【AI with ML】第 3 章 :超越基础知识:检测图像中的特征
- OpenCV(C++)图像处理基础04:图像混合(线性混合操作)