【问题标题】:How to add text in Deep Zoom Composer?如何在 Deep Zoom Composer 中添加文本?
【发布时间】:2010-07-26 08:32:46
【问题描述】:

我想在深度缩放作曲家中编写自己的项目,但是我想知道如何为每个放大的图像添加文本,就像 hard rock memorabilia

我想使用它,使用 silverlight 4.0

如您所见,在右窗格下,有关于图像的描述。

谢谢。

this http://www.freeimagehosting.net/uploads/43b14a3d53.png

【问题讨论】:

    标签: .net silverlight silverlight-4.0 deepzoom multiscaleimage


    【解决方案1】:

    这绝对是可行的。我做过类似的事情,效果很好。以下示例将显示特定于单击图像的信息。您可以根据是否希望在鼠标悬停、单击甚至缩放时显示信息来修改它。这完全取决于您。

    首先,将 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 没有被触发。谢谢
    • 你把绑定MouseLeftButtonDown事件的代码放在哪里了?
    • 这不正确。把它放在页面的代码隐藏中。您正在以编程方式绑定 MouseLeftButtonDown 事件。如果您的页面名为“MainPage.xaml”,则将绑定该 MouseLeftButtonDown 的代码放入 MainPage 类中。你写的 XAML 不会比我上面添加的多。
    【解决方案2】:

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

    问候。

    【讨论】:

    • 我也读过它,但根据这个博客projectsilverlight.blogspot.com/2008/03/… 它没有指定它使用pivot
    • 对..但我认为您的要求可以使用枢轴来完成..您需要问题中未提及的其他内容吗?
    【解决方案3】:

    创建 Hardrock Cafe Memrobilia 示例的公司Vertigo 已将其源代码发布到 CodePlex。在这里查看:http://bigpicture.codeplex.com/

    • 为了简化太多,您必须在 MultiScaleImage 上方收听 mouse movements

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

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

    【讨论】:

    • 您能否在您的项目符号 #3 中发布示例代码?谢谢
    • 我尝试实现上面的代码并且总是返回的“索引”是-1。它似乎永远不会拾取正确的索引。不知道我做错了什么。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-25
    相关资源
    最近更新 更多