Shape Tool
The Shape Tool is one of the tools, which come out-of-the-box with the RadImageEditor and allow you to draw different shapes over an image.
The tool could be added to the UI of RadImageEditor as shown in Example 1.
Example 1: Add Shape Tool
The namespaces that should be registered are as follows:
Example 2: Register namespaces
- Line: Allows to draw lines only with dragging.
- Rectangle: Draws rectangles or squares (when the LockRatio property is set to true)
- Ellipse: Allows you to create ellipses or circles (when the LockRatio property is set to true)
The Shape Tool provides an options to easily customize your shape – you can choose if the shape will be filled with some color or it will consist only of borders, which color and thickness also depends on your preferences. You could take advantage of the LockRatio property, which will ensure that the proportions of the shape will be always the same when resizing.
How to Create a Custom Shape
You could customize the shapes in the ShapeTool to fit specific requirements. To create a custom shape, the simple IShape interface should be implemented.
Example 3: Inherit the IShape interface
It exposes two members:
- string DisplayName: Тhe name, which will be displayed in the dropdown list.
- Geometry GetShapeGeometry: Тhe exact figure.
Example 4 shows a sample implementation of a custom shape.
Example 4: Implement custom shape
You could download runnable project with Custom Shape from our SDK repository
Add Custom Shape
After creating a custom shape, it should be registered in the tool. This could be achieved declaratively as well as in the code behind as shown in Examples 5 and 6. You could get or set the shapes in the ShapeTool trough the Shapes collection.