尝试更改图像DPI,而不更改文件大小

问题描述 投票:0回答:1

我有以下代码用于更改图像的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?

c# bitmap dpi
1个回答
0
投票

我认为您必须指出输出文件的格式,才能保存为JPEG之类的压缩图像格式。

newBitmap.Save(imagePathDestination, System.Drawing.Imaging.ImageFormat.Jpeg);
© www.soinside.com 2019 - 2024. All rights reserved.