.NET で特大の画像を表示しながらナビゲートする

ブログ カテゴリ: イメージング.NET

2020/05/13

この記事では、VintaSoft Imaging .NET SDKImageMapTool クラス を使用して、大きい画像や特大画像を表示する方法について説明します。

例として、画像サイズが 4067 メガピクセル (35878 x 113378 ピクセル) の JPEG2000 画像を使用しましょう。
以下は VintaSoft Imaging Demo で 1% 拡大した JPEG2000 画像のスクリーンショットです。
Very large JPEG2000 image with 1% zoom in VintaSoft Imaging Demo

以下は VintaSoft Imaging Demo で 10% 拡大した JPEG2000 画像のスクリーンショットです。
Very large JPEG2000 image with 10% zoom in VintaSoft Imaging Demo

非常に大きな画像を表示しているときに、現在画像のどの部分を表示しているのか、目的の場所に移動するにはどこに移動すればよいのかがわかりにくいことがよくあります。通常、この不便さは、画像を縮小してから目的の領域を拡大することで解決できます。ただし、画像のデコードに多くのリソースが消費される場合は、許容できないほどの時間がかかることがあります。 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 プロパティを使用すると、画像ビューアの表示領域 (黄色の四角形) の周囲の完全にキャッシュされた領域の四角形のサイズをメガピクセル単位で指定できます。以下のスクリーンショットは、画像ビューアの表示領域の周囲に 6 メガピクセルのキャッシュ領域がある画像ビューア設定を示しています。
Image viewer settings with custom size of cached area around visible area in image viewer



さらに、非常に大きな画像の場合、画像ビューア上で複数のImageMapTool要素を、それぞれ異なる相対的なスケールで同時に使用できます。これは、CompositeVisualToolクラスによって可能になります。このクラスは、複数のビジュアルツールの機能を組み合わせることができます。
画像ビューアで 2 つの画像マップを作成する方法を示す C# コードは次のとおりです。
// 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