这两天做了一个图片对比工具,里面要处理两张大的图片,所以要对图片先进行裁剪,下面看看我的方法吧
最开始用了
///
/// 裁剪图片
///
///
/// "c:\images\"
private List
{
var fileInfo = new FileInfo(imagePath);
if (!fileInfo.Exists)
throw new Exception("图片" + imagePath + "不存在!");
var savePathList = new List
var spath = savePath + fileInfo.Name.Replace(fileInfo.Extension, string.Empty);
try
{
var bitmap = new Bitmap(imagePath);
var format = bitmap.PixelFormat;
Bitmap cloneBitmap = bitmap.Clone(_cloneRect1, format);
var tempPath = spath + "_1.jpg-600";
cloneBitmap.Save(tempPath);
savePathList.Add(tempPath);
cloneBitmap.Dispose();
cloneBitmap = bitmap.Clone(_cloneRect2, format);
tempPath = spath + "_2.jpg-600";
cloneBitmap.Save(tempPath);
savePathList.Add(tempPath);
cloneBitmap.Dispose();
cloneBitmap = bitmap.Clone(_cloneRect3, format);
tempPath = spath + "_3.jpg-600";
cloneBitmap.Save(tempPath);
savePathList.Add(tempPath);
cloneBitmap.Dispose();
cloneBitmap = bitmap.Clone(_cloneRect4, format);
tempPath = spath + "_4.jpg-600";
cloneBitmap.Save(tempPath);
savePathList.Add(tempPath);
cloneBitmap.Dispose();
bitmap.Dispose();
return savePathList;
}
catch
{
throw new Exception("图片" + imagePath + "处理失败!");
}
}
以上就是c#利用Grahics进行图片裁剪的详细内容,更多请关注0133技术站其它相关文章!