我有以下代码用于更改图像的DPI:
public void changeDPI(string imagePathSource,string imagePathDestination,float DPIx,float DPIy)
{
Bitmap bitmap = new Bitmap(imagePathSource);
Bitmap newBitmap = new Bitmap(bitmap);
newBitmap.SetResolution(DPIx,DPIy);
newBitmap.Save(imagePathDestination);
}
但是,最终会更改文件的内存大小。示例测试图像的起始大小为267 KB,文件的newBitmap
版本最终为1.51 MB。如何在不更改文件大小的情况下更改DPI?
我认为您必须指出输出文件的格式,才能保存为JPEG之类的压缩图像格式。
newBitmap.Save(imagePathDestination, System.Drawing.Imaging.ImageFormat.Jpeg);