因此,我有一个应用程序需要原始图像,获取新的新裁剪区域,然后将裁切后的版本作为新文件保存。它的主要缺点是完美。新图像平均比原始图像大4倍。在我的测试中,我有一张大小约为4.5MB的照片,裁剪后的版本(正确裁剪并显得很好)在磁盘上大约为21MB。代码如下:Bitmap.Clone创建的图像比原始图像大4倍输出大小
var originalImage = new Bitmap(imagePath);
var fWidth = originalImage.PhysicalDimension.Width;
var fHeight = originalImage.PhysicalDimension.Height;
float calculatedWidth = GetCroppedWidth();
float calculatedHeight = GetCroppedHeight();
//Draw the image by centering the cropped region on the original
var heightOffset = (fHeight - calculatedHeight)/2;
var widthOffset = (fWidth - calculatedWidth)/2;
var sourceRectF = new RectangleF(widthOffset, heightOffset, calculatedWidth, calculatedHeight);
var croppedImage = originalImage.Clone(sourceRectF, originalImage.PixelFormat);
//Save the image
croppedImage.Save(croppedFileName);
什么是输入文件的图形格式? – leppie
对不起,我应该发布这是一个JPG格式。 – Llaslo