The following is an example of how Drawable might be used:
#include <Magick++.h>
using namespace std;
using namespace Magick;
int main(int argc,char **argv)
{
// Create base image (white
image of 600 by 400 pixels)
Image image( "600x400",
"xc:white" )
// Set draw options
image.penColor("red");
image.lineWidth(5) ;
// Draw a circle
Drawable drawable;
drawable.circle( 100,100,
150,150 );
image.draw( drawable );
// Draw a rectangle (re-use
drawable object)
drawable.rectangle( 200,200
300,300 );
image.draw( drawable );
// Display the result
image.display( );
}
Since Drawable is an object it may be saved in
an array or a list for later (perhaps repeated) use. Drawable depends on
the simple Coordinate class which represents a pair of x,y coodinates.
The methods provided by the Coordinate class are shown in the following
table:
|
|
|
|
void | Default Constructor |
double x_, double y_ | Constructor, setting x & y | |
|
double x_ | Set x coordinate |
void | Get x coordinate | |
|
double y_ | Set y coordinate |
void | Get y coordinate |
The methods available in the Drawable class are
shown in the following table:
|
|
|
|
double x_, double y_ | Draw a point using current pen color and thickness at coordinate |
Coordinate coordinate_ | ||
|
double startX_, double startY_, double endX_, double endY_ | Draw a line using current pen color and thickness using starting and ending coordinates |
Coordinate startCoordinate_, Coordinate endCoordinate_ | ||
|
double upperLeftX_, double upperLeftY_, double lowerRightX_, double lowerRightY | Draw a rectangle using current pen color and thickness from upper-left coordinates to lower-right coordinates |
Coordinate upperLeftCoordinate_, Coordinate lowerRightCoordinate_ | ||
|
double upperLeftX_, double upperLeftY_, double lowerRightX_, double lowerRightY | Draw a filled rectangle using current pen color from upper-left coordinates to lower-right coordinates |
Coordinate upperLeftCoordinate_, Coordinate lowerRightCoordinate_ | ||
|
double originX_, double originY_, double perimX_, double perimY_ | Draw a circle using current pen color and thicknews using specified origin and perimeter coordinates |
Coordinate originCoordinate_, Coordinate perimCoordinate_ | ||
|
double originX_, double originY_, double perimX_, double perimY_ | Draw a filled circle using current pen color, origin and perimeter coordinates |
Coordinate originCoordinate_, Coordinate perimCoordinate_ | ||
|
double originX_, double originY_, double width_, double height_, double arcStart_, double arcEnd_ | Draw an ellipse using current pen color, pen thickness, specified origin, width & height, as well as specified start and end of arc in degrees. |
Coordinate originCoordinate_, double width_, double height_, double arcStart_, double arcEnd_ | ||
|
double originX_, double originY_, double width_, double height_, double arcStart_, double arcEnd_ | Draw a filled ellipse using current pen color, specified origin, width & height, as well as specified start and end of arc in degrees. |
Coordinate originCoordinate_, double width_, double height_, double arcStart_, double arcEnd_ | ||
|
const std::list<Coordinate> &coordinates_ | Draw an arbitrary polygon using current pen color and pen thickness consisting of three or more coordinates contained in an STL list |
|
const std::list<Coordinate> &coordinates_ | Draw an arbitrary filled polygon using current pen color and pen thickness consisting of three or more coordinates contained in an STL list |
|
double x_, double y_, PaintMethod paintMethod_ | Color image according to paintMethod. The point method recolors the target pixel. The replace method recolors any pixel that matches the color of the target pixel. Floodfill recolors any pixel that matches the color of the target pixel and is a neighbor, whereas filltoborder recolors any neighbor pixel that is not the border color. Finally, reset recolors all pixels. |
Coordinate coordinate_, PaintMethod paintMethod_ | ||
|
double x_, double y_, PaintMethod paintMethod_ | Change the pixel matte value to transparent. The point method changes the matte value of the target pixel. The replace method changes the matte value of any pixel that matches the color of the target pixel. Floodfill changes the matte value of any pixel that matches the color of the target pixel and is a neighbor, whereas filltoborder changes the matte value of any neighbor pixel that is not the border color, Finally reset changes the matte value of all pixels. |
Coordinate coordinate_, PaintMethod paintMethod_ | ||
|
double x_, double y_, std::string text_ | Annotate image with text using current pen color, font, font pointsize, and box color (text background color), at specified coordinates. If text contains special format characters the image filename, type, width, height, or other image attributes may be incorporated in the text (see label()). |
Coordinate coordinate_, std::string text_ | ||
|
double x_, double y_, const string &image_ | Composite image (file) with image file at specified coordinates. |
Coordinate coordinate_, const std::string &image_ |