I want to draw some Rectangle over a single Image.
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?
If you already have an image opened in the editor select the rectangle tool by clicking its icon in the toolbar. To begin the drawing press in the image to set the starting point of the rectangle. With the mouse still pressed drag to create the rectangle. Release the mouse to complete drawing the rectangle.
cv2. rectangle() method is used to draw a rectangle on any image. Parameters: image: It is the image on which rectangle is to be drawn.
The rect() method creates a rectangle. Tip: Use the stroke() or the fill() method to actually draw the rectangle on the canvas.
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);
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>
Try this it also will help you.
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Multi_Textbox.Window1"
x:Name="Window"
Title="Window1"
Width="640" Height="480">
<Grid x:Name="LayoutRoot">
<Image Margin="104,50,75,99" Source="barkship.jpg"/>
<Rectangle Fill="#FF28B0DE" HorizontalAlignment="Left" Height="17.334" Margin="212,0,0,111.333" Stroke="Black" VerticalAlignment="Bottom" Width="99.667"/>
<TextBlock HorizontalAlignment="Left" Height="11" Margin="230.667,0,0,115" TextWrapping="Wrap" Text="CHANDRU" VerticalAlignment="Bottom" Width="63.333" Foreground="White"/>
</Grid>
It's output like this
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With