4

I'm looking for some c++ drawing graphics library to create rounded corners with anti-aliasing option for dynamic keyboard key creator. I've already tested OpenCV and Magick++ functions but the result was not so good. Can anyone help me with this?

This is a sample of one code to create a rounded corner with Magick++ library

void create_rounded_image (int size, int border) {
    Magick::Image image_bk (Magick::Geometry (size, size), Magick::Color ("black"));

    image_bk.strokeColor ("white");
    image_bk.fillColor ("white");
    image_bk.strokeWidth(1);
    image_bk.draw (DrawableCircle(size, size, size*0.3, size*0.3));

    image_bk.write ("rounded.png");
}

This is the result I'm getting

This is the result I'm getting

This is the result I'm looking for

This is the result I'm looking for

Lamar Latrell
  • 1,669
  • 13
  • 28
  • The first image show aliasing, I don't know Magick++ but there isn't there an option to activate anti aliasing ? – kebs May 05 '16 at 10:18
  • You can also go with Cairo (C API, although): http://www.cairographics.org/ – kebs May 05 '16 at 10:28

2 Answers2

1

Googling some online documentation, I found:

strokeAntiAlias - bool - Enable or disable anti-aliasing when drawing object outlines.

I suggest:

image_bk.strokeAntiAlias(true); 
Lamar Latrell
  • 1,669
  • 13
  • 28
0

Expanding on Lamar's answer. Magick::Image.strokeAntiAlias and Magick::DrawableStrokeAntiAlias is what you want. But I would suggest using std::list<Drawable> to generate a context stack. This would allow your application to manage what-will-be-drawn independently of image i/o.

using namespace Magick;

size_t size = 405;
size_t border = 6;

std::list<Drawable> ctx;
ctx.push_back(DrawableStrokeAntialias(MagickTrue));
ctx.push_back(DrawableStrokeColor("#CAF99B"));
ctx.push_back(DrawableStrokeWidth(border));
ctx.push_back(DrawableFillColor("#68C77B"));
ctx.push_back(DrawableCircle(size*0.75, size*0.25, size*0.33, size*0.66));

Image image_bk( Geometry(size, size), Color("white"));
image_bk.draw(ctx);

Rounded corners in C++

emcconville
  • 23,800
  • 4
  • 50
  • 66