DPI,图像宽度和高度与质量

DPI, Image width and height vs Quality

我正在使用以下函数创建 jpeg 图像

private static void Save(Bitmap bmp1, string path, ImageFormat format)
{
    bmp1.SetResolution(72,72);
    ImageCodecInfo jpgEncoder = GetEncoder(format);
    System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality;
    EncoderParameters myEncoderParameters = new EncoderParameters(1);
    myEncoderParameters.Param[0] = new EncoderParameter(myEncoder, 100L);

    bmp1.Save(path, jpgEncoder, myEncoderParameters);
}

private static ImageCodecInfo GetEncoder(ImageFormat format)
{

    ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();
    foreach (ImageCodecInfo codec in codecs)
    {
        if (codec.FormatID == format.Guid)
        {
            return codec;
        }
    }

    return null;
}

如您所见,我只使用这行代码中的 DPI bmp1.SetResolution(72,72);

我想知道输出看起来是否相同,72 DPI 版本如何适合网络以及在这种情况下 DPI 的真正效果是什么 提示:位图是由贝塞尔曲线生成的

首先,72 DPI 一直是显示设备的默认 DPI。打印 300。

SetResolution 实际上并没有改变外观。 "Use this method to set the desired resolution on a newly created bitmap. Changing the resolution of the image does not change its physical size."

它通常会影响 "how big" 将某些东西应用到设备上。调用 SetResolution 对其 spatial resolution.

没有影响

打印时,您设置图像的DPI;物理尺寸;和地图模式。尝试通过 300 DPI 激光打印机在 A4 sheet 纸上打印逻辑尺寸为 210 mm x 294 mm 的 72 DPI 图像将出现像素化(因为它被拉伸以填充整个 sheet ).

但是,如果您保持 DPI,而不是告诉 Windows 图像实际上是 50 mm x 50 mm,然后在同一台 300 DPI 打印机上再次打印到 A4,它不会出现像素化因为它更接近1:1(虽然现在图像比较小)。


重要的是要注意,在上面的两个示例中,位图并没有物理上改变,只是它的元尺寸和因此在纸上的结果大小。