C# 截取图像中的特定区域
来源:互联网 发布:淘宝网板鞋后底女鞋 编辑:程序博客网 时间:2024/05/17 22:04
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.Drawing.Imaging;
namespace CutPicture
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//加载图片
private void loadSrcBtn_Click(object sender, EventArgs e)
{
OpenFileDialog srcImageName = new OpenFileDialog();
if (srcImageName.ShowDialog() == DialogResult.OK)
{
Bitmap bmp = new Bitmap(Image.FromFile(srcImageName.FileName));
SrcImage.Image = bmp;
}
}
//截取图片 主要操作区域
private void cutImage(Point pos,int cutWidth, int cutHeight)
{
//先初始化一个位图对象,来存储截取后的图像
Bitmap bmpDest = new Bitmap(cutWidth, cutHeight, PixelFormat.Format32bppRgb);
//这个矩形定义了,你将要在被截取的图像上要截取的图像区域的左顶点位置和截取的大小
Rectangle rectSource = new Rectangle(pos.X, pos.Y, cutWidth, cutHeight);
//这个矩形定义了,你将要把 截取的图像区域 绘制到初始化的位图的位置和大小
//我的定义,说明,我将把截取的区域,从位图左顶点开始绘制,绘制截取的区域原来大小
Rectangle rectDest = new Rectangle(0, 0, cutWidth, cutHeight);
//第一个参数就是加载你要截取的图像对象,第二个和第三个参数及如上所说定义截取和绘制图像过程中的相关属性,第四个属性定义了属性值所使用的度量单位
g.DrawImage(SrcImage.Image, rectDest, rectSource, GraphicsUnit.Pixel);
//这是在GUI上显示被截取的图像
cutedImage.Image = (Image)bmpDest;
g.Dispose();
}
//保存截取的图片
private void saveCutImage_Click(object sender, EventArgs e)
{
SaveFileDialog saveImageName = new SaveFileDialog();
if (saveImageName.ShowDialog() == DialogResult.OK)
{
cutedImage.Image.Save(saveImageName.FileName);
}
}
//显示截取图片
private void showCutImageBtn_Click(object sender, EventArgs e)
{
Point pos = new Point(0, 0);
if (!(posX.Text == "" || posY.Text == ""))
{
pos.X = int.Parse(posX.Text);
pos.Y = int.Parse(posY.Text);
}
int cutWidth, cutHeight;
cutWidth = 20;
cutHeight = 20;
if (!(cutImageWidth.Text == "" || cutImageHeight.Text == ""))
{
cutWidth = int.Parse(cutImageWidth.Text);
cutHeight = int.Parse(cutImageHeight.Text);
}
this.cutImage(pos, cutWidth, cutHeight);
}
}
}
下面是demo的截图
- C# 截取图像中的特定区域
- C# 截取图像中的特定区域
- c# 图像截取
- C#截取图像中的任意部位任意形状
- IOS 截取指定区域的图像
- Halcon 算子 截取区域生成图像
- opencv将图像感兴趣区域截取出来
- 【Matlab图像处理】截取图像中的矩形区域(可不平行于坐标轴)并保存为图片
- MATLAB 标注 图像上截取Rect区域图像
- C#中将图片截取某一区域
- C#中的字符串截取
- OpenCV鼠标绘制矩形和截取图像的矩形区域
- opencv鼠标绘制矩形和截取图像的矩形区域
- halcon截取图像中被标记的区域
- python自动截取需要区域,进行图像识别实践!
- opencv截取图像中某一区域的方法
- c# 截取字符串两特定字符中间的字符
- C# indexof如何截取两个特定字符之间的字符串
- dedecms设计自己的网站
- 如何建立内核树
- 在eclipse中导入工程后@Override报错
- Think PHP 隐藏Index (URL重写)
- Cglib Dynamic Proxy(Cglib 动态代理)
- C# 截取图像中的特定区域
- 数据结构利器之私房STL(中)
- (2)字符转转化的题
- java 同步锁(synchronized)
- 启动hbase 报错 Address already in use 的解决办法
- OpenCV - undefined reference: SurfFeatureDetector and BruteForceMatcher
- Tap手势
- C#生成注册码及检验
- 国外几个主流的CMS系统