因此,我有一個應用程序需要原始圖像,獲取新的新裁剪區域,然後將裁切後的版本作爲新文件保存。它的主要缺點是完美。新圖像平均比原始圖像大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