在图像上绘制矩形 [英] Draw Rectangle over Image

查看:85
本文介绍了在图像上绘制矩形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想画一些矩形单个图像.

例如,我有以下(白色和黑色)飞船配置文件,并且我想在此配置文件中的特定位置添加一些(黄色和红色)矩形:

For example I have following (white and black) ship profile, and I want to add some (yellow and red) rectangles over this profile in specific locations:

有可能吗?我该怎么办?

Is it possible? How can I do this?

推荐答案

很有可能,如果您已经知道要突出显示的区域的x,y,宽度和高度,则可以将所有控件放入画布.

It's very possible, if you know the x, y, width and height of the areas that you want to highlight already you can place all of the controls in to a canvas.

您可以在下面的代码中设置矩形的属性,如下所示:

You can set the properties on the rectangles in code behind like this:

Rectangle rectangle = new Rectangle();
rectangle.SetValue(Canvas.LeftProperty, 10);
rectangle.SetValue(Canvas.TopProperty, 10);
rectangle.Width = 1000;
rectangle.Height = 50;
rectangle.Fill = new SolidColorBrush() { Color = Colors.Red, Opacity = 0.75f };

canvas.Children.Add(rectangle);

如果要在xaml中添加它们,可以这样.

and if you want to add them in xaml you can like this.

<Canvas>
    <Image Source="..."/>
    <Rectangle Canvas.Left="10" Canvas.Top="10" Width="1000" Height="50">
        <Rectangle.Fill>
           <SolidColorBrush Color="Red" Opacity="0.75"/>
        </Rectangle.Fill>
    </Rectangle>                        
</Canvas>

这篇关于在图像上绘制矩形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆