Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw Rectangle over Image

Tags:

.net

image

wpf

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:

enter image description here

Is it possible? How can I do this?

like image 240
Nick Avatar asked Jun 13 '12 11:06

Nick


People also ask

How do I add a rectangle to a photo?

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.

How do you draw a rectangle on a picture in Python?

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.

How do you make a rectangle picture on canvas?

The rect() method creates a rectangle. Tip: Use the stroke() or the fill() method to actually draw the rectangle on the canvas.


2 Answers

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>
like image 175
Andy Avatar answered Sep 22 '22 02:09

Andy


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

Result

like image 30
CHANDRA Avatar answered Sep 26 '22 02:09

CHANDRA