显示具有重叠多边形的图像
这看起来很简单,但对我来说不起作用。我想显示来自我的数据库的图像,并使用相同的坐标系覆盖来自同一数据库的多边形。
<Image Name="imgColl" Stretch="Fill" MaxWidth="190" MinHeight="70">
<Image.Source>
<DrawingImage>
<DrawingImage.Drawing>
<DrawingGroup>
<ImageDrawing ImageSource="{Binding ImageData}" Rect="0,0,590,590"/>
<GeometryDrawing Geometry="{Binding Coordinates, StringFormat=M\{0\}}">
<GeometryDrawing.Pen>
<Pen Thickness="4" LineJoin="Bevel" Brush="OrangeRed"/>
</GeometryDrawing.Pen>
</GeometryDrawing>
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
</Image.Source>
</Image>
我发现我必须在 ImageDrawing 对象上指定 Rect。不幸的是,因为我加载的图像尺寸不同。但如果我不指定矩形,则运行应用程序时不会出现图像。如果我使图像足够大(如示例中所示),图像确实会出现,并且会调整大小以适合我的控制,但多边形坐标系似乎不匹配。
另外,我使用 StringFormat 将 M 放在 Geometry 规范前面,这样它就如下所示:“M50,50,12,50,30,30,30,100,100,100”。如果我明确指定,则会出现多边形,但如果我使用相同的字符串将其绑定,则不会出现多边形。
不确定这两个问题是否相互关联——当这两个问题中的任何一个得到解决时,我将不得不重新评估。感谢您提供的任何指导!
This seems simple, but it's not working for me. I'd like to display an image from my DB, and overlay a polygon from the same DB, using the same coordinate system.
<Image Name="imgColl" Stretch="Fill" MaxWidth="190" MinHeight="70">
<Image.Source>
<DrawingImage>
<DrawingImage.Drawing>
<DrawingGroup>
<ImageDrawing ImageSource="{Binding ImageData}" Rect="0,0,590,590"/>
<GeometryDrawing Geometry="{Binding Coordinates, StringFormat=M\{0\}}">
<GeometryDrawing.Pen>
<Pen Thickness="4" LineJoin="Bevel" Brush="OrangeRed"/>
</GeometryDrawing.Pen>
</GeometryDrawing>
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
</Image.Source>
</Image>
I find that I have to specify the Rect on the ImageDrawing object. This is unfortunate because the images I'm loading are of different sizes. But if I don't specify the Rect, the image doesn't appear when running the app. If I make the image big enough (as in the example), the image does appear, and it gets resized to fit my control, but the polygon coordinate system doesn't seem to match.
Also, I've used StringFormat to put an M in front of the Geometry specification, so that it comes out like this: "M50,50,12,50,30,30,30,100,100,100". If I specify that explicitly, the polygon appears, but if I bind it with the same string, the polygon doesn't appear.
Not sure if those two problems are related to one another--I'll have to re-evaluate when either of the two is fixed. Thanks for any guidance you have to offer!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此处忽略绑定的
StringFormat
设置,因为绑定的目标类型不是字符串,而是 几何。由
Cooperatives
属性返回的字符串会隐式转换为 Geometry,因为 Geometry 有[TypeConverterAttribute(typeof(GeometryConverter))]
属性设置,但 StringFormat 不会予以应用。您需要添加绑定转换器。对于有关
ImageDrawing.Rect
的另一个问题:据我了解ImageDrawing,您总是必须指定绘图矩形,默认情况下它是Rect.Empty
。也许您还可以将 Rect 属性绑定到数据对象的某些属性。不管怎样,为了维护图像和多边形的公共坐标系,定义这样的东西不是更简单吗?
The
StringFormat
setting of the binding is ignored here, since the target type of the binding is not a string, but a Geometry.The string returned by your
Coordinates
property is implicitly converted into a Geometry, because Geometry has a[TypeConverterAttribute(typeof(GeometryConverter))]
attribute setting, but the StringFormat won't be applied . You will need to add a binding Converter.For the other problem concerning
ImageDrawing.Rect
: as far as i've understood ImageDrawing, you always have to specify the drawing rectangle, it isRect.Empty
by default. Maybe you can also bind theRect
property to some property of your data object.Anyway, wouldn't it be a lot simpler to define something like this, in order to maintain a common coordinate system for image and polygon?