Jul 8, 2010

Image Magick: Drawing some shapes

I need to draw some primitive shapes like circle, rectangle using image magick.
Here are the c++ codes that draws this shape.
Image img = new Image("100x100","black");

Line:
-----
img->draw( DrawableLine( centroid.first, centroid.second, static_cast(ev_x), static_cast(ev_y) ));

Circle Unfilled:
----------------
img->strokeColor("yellow");
img->fillColor("none");
img->draw(DrawableCircle(centroid.first, centroid.second, centroid.first + 25, centroid.second));

This code draws a circle of radius 25 pixels. The arguments it takes are
center_x, center_y, periemter_x, and periemeter_y.
It calculates the radius from the perimeter coordinates. That is why just provide any point on the circle as perimeter_x,perimeter_y.

To draw a filled circle just remove the second line.


Rectangle:
----------
img->draw(DrawableLine(centroid.first - 25, centroid.second - 25, centroid.first + 25, centroid.second - 25));
img->draw(DrawableLine(centroid.first + 25, centroid.second - 25, centroid.first + 25, centroid.second + 25));
img->draw(DrawableLine(centroid.first + 25, centroid.second + 25, centroid.first - 25, centroid.second + 25));
img->draw(DrawableLine(centroid.first - 25, centroid.second + 25, centroid.first - 25, centroid.second - 25));

Draws a rectangle using the lines from the centroid.
Rectangles can also be drawn using DrawableRectangle(). The arguments are respectively,
upper_left_x, upper_left_y, lower_left_x and lower_left_y
img->draw(DrawableLine(centroid.first - 5, centroid.second - 5, centroid.first + 5, centroid.second + 5));
Magick++

No comments:

Down with the Dictatorship!

    "Let them hate me, so that they fear me" - Caligula 41AD