【发布时间】:2016-09-26 09:20:17
【问题描述】:
在我的项目中,我必须调整图像大小,然后将其保存到文件夹中。但是,我遇到了一个问题,即某些图像会大于原始文件的大小。
调整大小方法:
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,文件大小:6076KB
第二次保存图片:1824*1026,文件大小:7311KB
图片:
更新
原图的Bit depth是24,resize后是32,问题出在这里吗?
【问题讨论】:
-
您确定将其保存为 BMP 格式吗?
-
@Euphoric,是的!您可以查看上面的图片网址!是 XXXX.bmp 图片
-
也许原始图像是 16 bpp,输出是 24 bpp?
-
@i486 OOOOOOOH,原来的位深度是24,调整大小是32!!!!!!!!!但是,如何解决呢???