在 .NET 中查看超大图像时进行导航

博客类别:成像.NET

2020/05/13

本文介绍如何使用 ImageMapTool 类(来自 VintaSoft Imaging .NET SDK)查看大型和超大型图像。

我们以一张 4067 兆像素(35878×113378 像素)的 JPEG2000 图像为例。
以下是 JPEG2000 图像放大 1% 后的屏幕截图。 VintaSoft Imaging Demo:
Very large JPEG2000 image with 1% zoom in VintaSoft Imaging Demo

以下是 JPEG2000 图像在 10% 缩放比例下的屏幕截图 VintaSoft Imaging Demo:
Very large JPEG2000 image with 10% zoom in VintaSoft Imaging Demo

在查看超大图像时,通常很难分辨当前位于图像的哪个部分,以及如何移动到目标位置。通常,可以通过缩小图像,然后再放大所需区域来解决此问题。但是,如果图像解码非常消耗资源,则可能需要花费大量时间。使用 ImageMapTool 类(ImageMapTool)进行图像映射是一种便捷优雅的解决方案。

VintaSoft Imaging Demo 中,可以使用菜单项"视图 -> 图像映射设置..."启用图像映射。下面的屏幕截图显示了 VintaSoft Imaging Demo 中的图像映射设置:
Default image map settings in VintaSoft Imaging Demo


实际上,图像地图是一个小型图像查看器,它位于主图像查看器上方,显示相同的图像,但缩放模式不同。以下屏幕截图显示了相对于主图像查看器当前缩放比例为 1/25 的图像映射设置:
Image map settings with custom scale factor in VintaSoft Imaging Demo


ImageMapTool 类:

ImageViewer.ViewerBufferSize属性允许指定图像查看器中可见区域(黄色矩形)周围完全缓存区域的矩形大小(以兆像素为单位)。以下屏幕截图显示了图像查看器设置,其中图像查看器可见区域周围缓存区域的大小为 600 万像素:
Image viewer settings with custom size of cached area around visible area in image viewer



此外,对于非常大的图像,可以在图像查看器中同时使用多个 ImageMapTool 元素,每个元素具有不同的相对缩放比例。这得益于 CompositeVisualTool 类,该类允许组合多个可视化工具的功能。
以下 C# 代码展示了如何在图像查看器中创建 2 个图像映射:
// create the first image map tool
Vintasoft.Imaging.UI.VisualTools.ImageMapTool imageMap1 = new Vintasoft.Imaging.UI.VisualTools.ImageMapTool();
// specify that image map must be enabled
imageMap1.Enabled = true;
// specify that image map tool must show image in best fit mode
imageMap1.Zoom = 0;
// specify that image map must have size 200x200 pixels
imageMap1.Size = new System.Drawing.Size(200, 200);
// specify that image map must be shown at the left-top corner of image viewer
imageMap1.Anchor = Vintasoft.Imaging.UI.AnchorType.Left | Vintasoft.Imaging.UI.AnchorType.Top;
// specify that image map tool border must have red color
imageMap1.CanvasPen = new System.Drawing.Pen(System.Drawing.Color.Red);
// specify that the border of image's visible region in image map must have lime color
imageMap1.VisibleRectPen = new System.Drawing.Pen(System.Drawing.Color.Lime);

// create the second image map tool
Vintasoft.Imaging.UI.VisualTools.ImageMapTool imageMap2 = new Vintasoft.Imaging.UI.VisualTools.ImageMapTool();
// specify that image map must be enabled
imageMap2.Enabled = true;
// specify that image map tool must show image in 1/25 scale from image viewer zoom
imageMap2.Zoom = 1 / 25f;
// specify that image map must have size 200x200 pixels
imageMap1.Size = new System.Drawing.Size(200, 200);
// specify that image map must be shown at the left-bottom corner of image viewer
imageMap2.Anchor = Vintasoft.Imaging.UI.AnchorType.Left | Vintasoft.Imaging.UI.AnchorType.Bottom;
// specify that image map tool border must have red color
imageMap2.CanvasPen = new System.Drawing.Pen(System.Drawing.Color.Red);
// specify that the border of image's visible region in image map must have lime color
imageMap2.VisibleRectPen = new System.Drawing.Pen(System.Drawing.Color.Lime);

// create composite visual tool that combines first and second image map tools
Vintasoft.Imaging.UI.VisualTools.CompositeVisualTool compositeVisualTool = new Vintasoft.Imaging.UI.VisualTools.CompositeVisualTool(imageMap1, imageMap2);

// set composite visual tool as current visual tool of image viewer
imageViewer1.VisualTool = compositeVisualTool;

以下屏幕截图显示了带有 2 个图像映射的图像查看器:
Image viewer with 2 image maps in VintaSoft Imaging Demo