在我的項目中,我必須調整圖像大小,然後將其保存到文件夾中。但是,我遇到了一些問題,其中一些圖像會比原始文件大小大。爲什麼我的BMP圖像在縮小寬度和高度後比原始圖像大?
大小調整方法:
public Image reduce(Image sourceImage, string size)
{
double percent = Convert.ToDouble(size)/100;
int width = (int)(sourceImage.Width * percent);
int height = (int)(sourceImage.Height *percent);
var resized = new Bitmap(original, width, height);
return resized;
}
使用:
//the code to get the image is omitted (in my testing, bmp format is fixed, however, other image formats are required)
//to test the size of original image
oImage.Save(Path.Combine(oImagepath), System.Drawing.Imaging.ImageFormat.Bmp);
Image nImage = resizeClass.reduce(oImage,"95");
nImage.Save(Path.Combine(nImagepath), System.Drawing.Imaging.ImageFormat.Bmp);
結果:
圖像的第一保存:1920×1080,尺寸:6076 KB
圖像的第二保存:1824 * 1026,尺寸:
- original
: 7311KB < =它應該比6076KB
圖像少
更新
原始圖像的位深是24調整爲32。是這裏的問題?
你絕對相信你將其保存爲BMP? – Euphoric
@欣快,是的!你可以檢查上面的圖片網址!它是XXXX.bmp圖像 –
也許原始圖像是16 bpp和輸出是24 bpp? – i486