如何在Deep Zoom Composer中添加文本?

7
3个回答

5
这绝对是可行的。我做过类似的事情,效果很好。以下示例将显示与所选图像相关的信息。您可以根据需要进行修改,以便在悬停、单击甚至缩放时显示信息。完全由您决定。
首先,在您的画布上添加一个MultiScaleImage...
<MultiScaleImage  x:Name="deepZoomObject" Source="/GeneratedImages/dzc_output.xml" />

在画布的其他位置,添加一个TextBlock用于显示信息:

<TextBlock X:Name="tbInfo" />

接下来,创建一个类来保存每个“瓷砖”的信息,添加一些虚拟信息,并将一堆瓷砖添加到列表中:

    public class TileDetail {
       public int Index { get; set; } 
       public string TileName { get; set; }
    }
    //The Index is the zero based index of the images.  It depends on the index created by DeepZoomComposer.  This is the one piece of information that you absolutely need to know.  I believe the index is based on the order that the images are added to DeepZoomComposer but test to make sure.

   List<TileDetail> TileDetailsList = new List<TileDetail>();

   TitleDetail td1 = new TileDetail();
   td1.Index = 0;
   td1.TileName = "Tile #1";

   TileDetailsList.Add(td1);

   TitleDetail td21 = new TileDetail();
   td2.Index = 1;
   td2.TileName = "Tile #2";

   TileDetailsList.Add(td2);

   //Repeat the above for your remaining tiles always incrementing the Index.  If you're loading information from a DB then you'll need to make sure to have a way to connect the image to its index from DeepZoomComposer.

现在列表已经充满了瓷砖信息,我们需要连接MouseLeftButtonDown事件处理程序以检测图像何时被点击,并最终确定所点击图像的索引。有了索引,我们只需要搜索我们的列表以获取适当的瓷砖详细信息,然后在画布上显示。

在您的代码后台中,请添加以下内容:

   deepZoomObject.MouseLeftButtonDown += delegate(object sender, MouseButtonEventArgs e)
   {
      //Get the index of the image
      int index = GetIndexOfSubImage(e.GetPosition(deepZoomObject));
      //Find the image in the list of images
      TileDetail td = TileDetailsList.FirstOrDefault(t => t.Index == index);
      //Display image info
      tbInfo.Text = td.TileName;
   };

以下是“秘密武器”,它将找到所点击图片的索引。
   private int GetIndexOfSubImage(Point point)
   {
      // Test each subimage to find the image where the mouse is within
      for (int i = deepZoomObject.SubImages.Count - 1; i >= 0; i--)
      {
        MultiScaleSubImage image = deepZoomObject.SubImages[i];
        double width = deepZoomObject.ActualWidth / (deepZoomObject.ViewportWidth * image.ViewportWidth);
        double height = deepZoomObject.ActualWidth / (deepZoomObject.ViewportWidth * image.ViewportWidth * image.AspectRatio);

        Point pos = deepZoomObject.LogicalToElementPoint(new Point(image.ViewportOrigin.X / image.ViewportWidth, -image.ViewportOrigin.Y / image.ViewportWidth));
        Rect rect = new Rect(pos.X, pos.Y, width, height);

        if (rect.Contains(point))
        {
           // Return the image index
           return i;
        }
      }    
      return -1; //if there is no corresponding subimage
    }

就是这样。只要您的图像索引在列表中有相应的图像,那么在MultiScaleImage对象内单击图像将显示图像信息。


你能否发布一个可运行的代码,这样我就可以尝试一下?我已经尝试实现它了,但是MouseLeftButtonDown没有被触发。谢谢。 - xscape
你把绑定MouseLeftButtonDown事件的代码放在哪里了? - NakedBrunch
那不正确。将其放在页面的代码后面。您正在以编程方式绑定MouseLeftButtonDown事件。如果您的页面名为“MainPage.xaml”,则将绑定MouseLeftButtonDown的代码放在MainPage类中。您不需要编写比我上面添加的更多XAML。 - NakedBrunch

1

看起来不只是简单的DeepZoom。他们在你刚提到的项目中使用的是Silverlight的MS Live Lab Pivot Control。http://www.getpivot.com/。 这个网站有很好的教程,可以开始使用Pivot,而且创建集合非常简单。

敬礼。


我也读过相关内容,但根据这篇博客http://projectsilverlight.blogspot.com/2008/03/dissecting-hard-rock-memorabilia-and.html,它并没有指明使用了枢轴。 - xscape
没错,但我认为你的要求可以使用数据透视表来完成.. 你需要其他在问题中没有提到的东西吗? - Shoaib Shaikh

0

Vertigo公司创建的Hardrock Cafe Memrobilia示例已经在CodePlex上公开了源代码。在这里查看:http://bigpicture.codeplex.com/

  • 为了简化事情,你需要监听MultiScaleImage上方的鼠标移动

  • 在每次鼠标移动时,您应该遍历MultiScaleImage子图像集合,并检查哪些图像在鼠标指针下面。

  • 为了识别不同的图像,DeepZoom集合中的每个图像都应具有一个唯一标识符 - 例如,在DeepZoomComposer中,您可以向每个图像添加一个tag值。基于该标记,您可以从其他XML文件中找到适当的信息文本以显示给用户。


请问您能否在第三条中发布一段示例代码?谢谢。 - xscape
我尝试实现上面的代码,但总是返回“Index”为-1。它似乎从来没有选择正确的索引。不确定我做错了什么。 - user603830

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接