WPF DeepZoom 研究记录

2022-05-07 16:12:09 浏览数 (1)

以前搞silverlight的时候deepzoom挺酷的,这几天玩WPF的时候居然发现不支持deepzoom。这不是开玩笑么。google了几回,找到个开源的deepzoom for wpf 。这个控件配合Deep Zoom Composer确实可以实现。不过貌似只能用单张图片导出。

不过这样只能依靠Deep Zoom Composer,如果是动态的图片呢?不方便。于是反编译了下Deep Zoom Composer。大概研究了下,没有注释看的我蛋疼啊==!。

折腾了一下午终于实现了图片的导出,不过只能导出一张,几张合并的时候还是不行,先这样吧。

代码语言:javascript复制
public  class DZImageHelper
   {
       public  static  void CreateImage(string dest)
       {
           var imgList = new List<Image>();
           imgList.Add( new Image("E:\IMGTEST\1.jpg"));

           var creator = new SparseImageCreator();
           SetCommonImageCreatorParams(creator);

           try
           {
               creator.Create(imgList, dest   "\output");
           }
           catch (Exception ex)
           {
               throw ex;
           }
       }

       private static void SetCommonImageCreatorParams(CreatorBase creator)
       {
           creator.TileFormat = ImageFormat.Jpg;
           creator.ImageQuality = 0.5;
           creator.TileOverlap = 1;
           creator.TileSize = 64;
       }
   }
代码语言:javascript复制
窗体:
代码语言:javascript复制
<Window x:Class="DeepZoomForWPF.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Controls="clr-namespace:DeepZoom.Controls;assembly=DeepZoom" Title="MainWindow" Height="600" Width="1000"
         Loaded="Window_Loaded">
    <Grid>
        <Controls:MultiScaleImage x:Name="msi" Width="Auto" Height="Auto"/>
    </Grid>
</Window>

后台代码:
代码语言:javascript复制
using System;
using System.Windows;
using DeepZoom;


namespace DeepZoomForWPF
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            string dest = AppDomain.CurrentDomain.BaseDirectory;
            DZImageHelper.CreateImage(dest);
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            string url = AppDomain.CurrentDomain.BaseDirectory   "output.xml";
            this.msi.Source = new DeepZoomImageTileSource(new Uri( url, UriKind.Absolute));
        }
    }
}

注:需要导入三个DLL

0 人点赞