SetResolution

RasterImage.SetResolution method

为此设置分辨率RasterImage .

public virtual void SetResolution(double dpiX, double dpiY)
范围类型描述
dpiXDouble水平分辨率(以每英寸点数为单位)RasterImage.
dpiYDouble垂直分辨率(以每英寸点数为单位)RasterImage.

例子

以下示例显示了如何设置光栅图像的水平/垂直分辨率。

[C#]

string dir = "c:\\temp\\";

using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.jpg"))
{
    Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;

    // 获取图像的水平和垂直分辨率
    double horizontalResolution = rasterImage.HorizontalResolution;
    double verticalResolution = rasterImage.VerticalResolution;
    System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", horizontalResolution);
    System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", verticalResolution);

    if (horizontalResolution != 96.0 || verticalResolution != 96.0)
    {
        // 使用 SetResolution 方法在一次调用中更新两个分辨率值。
        System.Console.WriteLine("Set resolution values to 96 dpi");
        rasterImage.SetResolution(96.0, 96.0);

        System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", rasterImage.HorizontalResolution);
        System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", rasterImage.VerticalResolution);
    }

    // 输出可能如下所示:
    // 水平分辨率,以每英寸像素为单位:300
    // 垂直分辨率,以每英寸像素为单位:300
    // 将分辨率值设置为 96 dpi
    // 水平分辨率,以每英寸像素为单位:96
    // 垂直分辨率,以每英寸像素为单位:96
}

也可以看看