切割我做好了,代码如下:
private void toolStripButton切割_Click(object sender, EventArgs e)
{
RasterImage imgCopy;
// 取得您需要切割的部分
LeadRect rc = rasterImageViewer1.Image.GetRegionBounds(null);
// 将这一部分变为一张图片
imgCopy = new RasterImage(rasterImageViewer1.Image.Clone(rc));
// 调用裁剪方法对原始图像裁剪,去掉切割的部分
LeadRect newRc = new LeadRect();
if(rc.Width>rc.Height)//上下切割
{
//获取左下角
if(rc.Top>rasterImageViewer1.Image.Height-rc.Bottom) //所选区域在下面
{
newRc = new LeadRect(0, 0, rasterImageViewer1.Image.Width, rc.Top);
}else
{
newRc = new LeadRect(0, rc.Bottom, rasterImageViewer1.Image.Width, rasterImageViewer1.Image.Height - rc.Bottom);
}
}else
{
//左右切割
//获取右下角
if(rc.Left>rasterImageViewer1.Image.Width-rc.Right) //所选区域在右边
{
newRc = new LeadRect(0, 0, rc.Left, rasterImageViewer1.Image.Height);
}
else
{
newRc = new LeadRect(0, rc.Right, rasterImageViewer1.Image.Width-rc.Right, rasterImageViewer1.Image.Height);
}
}
CropCommand command = new CropCommand();
command.Rectangle = newRc;
command.Run(rasterImageViewer1.Image);
//一般切割是针对单张图片,可以在原文件名后加-1,以便保存。
string twoTiffFile = realImageFile.Substring(0, realImageFile.LastIndexOf(".tif")) + "-1.tif";
//之后分别保存
//保存原图片
saveToTiffFile();
//保存切割后的图片
_pageMode = CodecsSavePageMode.Overwrite;
codecs.Save(imgCopy,
twoTiffFile,
imgCopy.OriginalFormat,
imgCopy.BitsPerPixel,
1,
1,
1,
_pageMode);
//刷新LISTVIEW1
} |