VerticalResolution

BmpImage.VerticalResolution property

获取或设置此对象的垂直分辨率,以每英寸像素为单位RasterImage .

public override double VerticalResolution { get; set; }

适当的价值

垂直分辨率。

评论

请注意,默认情况下,此值始终为 96,因为不同的平台无法返回屏幕分辨率。您可以考虑使用 SetResolution 方法在一次调用中更新两个分辨率值。

例子

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

[C#]

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

using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.bmp"))
{
    Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;

    // 获取 BmpImage 的水平和垂直分辨率
    double horizontalResolution = bmpImage.HorizontalResolution;
    double verticalResolution = bmpImage.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");
        bmpImage.SetResolution(96.0, 96.0);

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

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

以下示例获取有关图像的一般信息,包括像素格式、图像大小、分辨率、压缩等。

[C#]

using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\sample.bmp"))
{
    Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;                

    System.Console.WriteLine("The pixel format: {0}", bmpImage.RawDataFormat);                
    System.Console.WriteLine("The raw line size in bytes: {0}", bmpImage.RawLineSize);
    System.Console.WriteLine("The bitmap compression: {0}", bmpImage.Compression);
    System.Console.WriteLine("The bitmap width: {0}", bmpImage.Width);
    System.Console.WriteLine("The bitmap height: {0}", bmpImage.Height);
    System.Console.WriteLine("The number of bits per pixel: {0}", bmpImage.BitsPerPixel);

    double hres = bmpImage.HorizontalResolution;
    double vres = bmpImage.VerticalResolution;
    System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", hres);
    System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", vres);

    if (hres != 96.0 || vres != 96.0)
    {
        // 您可以考虑使用 SetResolution 方法在一次调用中更新两个分辨率值。
        System.Console.WriteLine("Set resolution values to 96 dpi");
        bmpImage.SetResolution(96.0, 96.0);

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

    //输出可能如下所示:
    //像素格式:RGB24Bpp,使用通道:8,8,8
    //原始行大小(以字节为单位):1500
    //位图压缩:RGB
    //位图宽度:500
    //位图高度:375
    //每个像素的位数:24
    //水平分辨率,以每英寸像素为单位:0
    //垂直分辨率,以每英寸像素为单位:0
    //将分辨率值设置为96 dpi
    //水平分辨率,以每英寸像素为单位:96.012
    //垂直分辨率,以每英寸像素为单位:96.012
}

也可以看看