2011-11-30 86 views
1

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

什麼是輸入文件的圖形格式? – leppie

+0

對不起,我應該發佈這是一個JPG格式。 – Llaslo

回答

2

這聽起來像你加載的圖像是一些其他格式比BMP(例如PNG或JPG)。

使用Bitmap.Save另一重載指定的ImageFormat

+0

就是這樣。感謝您的幫助! – Llaslo

0

看那Bitmap.Save overload,讓你選擇輸出格式。 默認情況下,它是Bmp我猜,它沒有壓縮。

所以,你的情況使用

croppedImage.Save(croppedFileName, originalImage.RawFormat); 
+1

感謝您的輸入!我很感激。 – Llaslo

相關問題