4

我有一个用户可以缩放/滚动的图像。我想在不同的图层上绘制一些矩形/圆圈(例如:为图片中识别的每个人的脸部绘制一个圆圈)。

矩形位置是相对于图像的。

如何创建这样的叠加层?

4

2 回答 2

7

一种简单的方法是使用 Canvas 并将画布的背景属性设置为您的照片,然后将圆形或矩形放在其上,并使用 Canvas.Left 和 .Top 属性定位它们。

    <Canvas x:Name="myCanvas">
        <Canvas.Background>
            <ImageBrush ImageSource="c:\photo.bmp"/>
        </Canvas.Background>
        <Image Canvas.Top="20" Canvas.Left="20" Height="20" Width="20" Source="c:\circle.bmp"/>
    </Canvas>
于 2009-11-24T15:58:11.163 回答
5

我设法做了类似的事情:

  • 将图像设置为背景
  • ItemsControl在上面放一个透明的
  • 设置ItemsControl.ItemsPanelCanvas
  • 为拖动操作编写处理程序

代码片段:

  <ItemsControl x:Name="overlayItemsControl" 
        Background="Transparent"  
        ItemsSource="{Binding Path=Blocks}"
        Width="{Binding ElementName=imageControl, Path=Width}"
        Height="{Binding ElementName=imageControl, Path=Height}"
        ItemContainerStyle="{StaticResource rectStyle}"
        PreviewMouseMove="ItemsControl_PreviewMouseMove"
        PreviewMouseDown="ItemsControl_PreviewMouseDown"
        PreviewMouseUp="ItemsControl_PreviewMouseUp"
        PreviewKeyDown="ItemsControl_PreviewKeyDown">

        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <Canvas IsItemsHost="True" />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
   ....
</ItemsControl>
于 2009-04-13T12:59:05.133 回答