Skip to content

Instantly share code, notes, and snippets.

@hhatto
Created April 3, 2015 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hhatto/2520ba059335975bc15a to your computer and use it in GitHub Desktop.
Save hhatto/2520ba059335975bc15a to your computer and use it in GitHub Desktop.
generate image for stroke width 2.0 and 3.0 on C++
#include <stdio.h>
#include <Magick++.h>
using namespace Magick;
void gen_line_png(float line_width)
{
Image image = Image(Geometry(200, 200), Color("white"));
char filename[50];
CoordinateList coords;
DrawableList drawables;
Color blankColor;
Color ptColor = Color("magenta");
Color lineColor = Color("red");
image.type(TrueColorMatteType);
drawables.push_back(DrawableFillColor(ptColor));
drawables.push_back(DrawableStrokeColor(ptColor));
int i, x, y, height, width;
float r = 1.0;
height = image.size().height();
width = image.size().width();
int v[6][2] = {{50,50}, {75,60}, {100,80}, {150,150}, {150,30}, {180,10}};
for (i = 0; i < 6; ++i) {
x = v[i][0]; y = v[i][1];
coords.push_back(Coordinate(x, height - y));
y = height - y;
drawables.push_back(DrawableCircle(x, y, x + r, y + r));
}
drawables.push_back(DrawableFillColor(blankColor));
drawables.push_back(DrawableStrokeColor(lineColor));
drawables.push_back(DrawableStrokeLineJoin(RoundJoin));
drawables.push_back(DrawableStrokeWidth(line_width));
drawables.push_back(DrawablePolyline(coords));
image.draw(drawables);
sprintf(filename, "test-im%d.png", int(line_width));
image.write(filename);
}
int main(int argc, char **argv)
{
InitializeMagick(*argv);
gen_line_png(2.0);
gen_line_png(3.0);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment