Cross-platform drawing library

2019-02-01 02:09发布

问题:

I've been looking for a good cross-platform 2D drawing library that can be called from C++ and can be used to draw some fairly simple geometry; lines, rectangles, circles, and text (horizontal and vertical) for some charts, and save the output to PNG.

I think a commercial package would be preferable over open source because we would prefer not to have to worry about licensing issues (unless there's something with a BSD style license with no credit clause). I've looked at Cairo Graphics which seemed promising, but the text rendering looks like crap out of the box, and upgrading the text back-end brings us into murky license land.

I need it for Windows, Mac and Linux. Preferably something fairly lightweight and simple to integrate. I've thought about Qt but that's way too heavy for our application.

Any ideas on this would be awesome.

回答1:

Try Anti-Grain Geometry. From the description:

Anti-Grain Geometry (AGG) is an Open Source, free of charge graphic library, written in industrially standard C++. The terms and conditions of use AGG are described on The License page. AGG doesn't depend on any graphic API or technology. Basically, you can think of AGG as of a rendering engine that produces pixel images in memory from some vectorial data. But of course, AGG can do much more than that. The ideas and the philosophy of AGG are:

  • Anti-Aliasing.
  • Subpixel Accuracy.
  • The highest possible quality.
  • High performance.
  • Platform independence and compatibility.
  • Flexibility and extensibility.
  • Lightweight design.
  • Reliability and stability (including numerical stability).


回答2:

Another one: Skia. Used in Android and Chrome, under active development, HW acceleration.



回答3:

Have a look at SFML. It's open source but the license is very permissive.

Drawing simple shapes
Displaying text



回答4:

Antigrain does high quality primitive rendering and seems to be able to render true type fonts and has a commercial license available upon request.

http://www.antigrain.com/



回答5:

Use SDL



回答6:

Have you tried FLTK? It is lightweight, cross-platform, has support for 2D/3D graphics and comes with a good widget set (including a charting component). The API is simple and straight forward.



回答7:

There is also libgd - simple one, but well-written.

Regarding Cairo Graphics, I can't believe it renders text that looks bad. If you are particularly concerned about text rendering, State of the Text Rendering from Jan 2010 gives quite good overview.



回答8:

I use CImg: cross platform (self contained single header file), simple, concise. PNG is not natively supported but can be handled if ImageMagick is installed (see supported formats).

See also this related question.



回答9:

You might use Allegro 5 (since SDL and SFML are mentioned). This provides all of the platforms you require (and more) and can render shapes and save to PNG. Version 5 has a much improved API and hardware acceleration. With any of these low level cross platform libraries you'd have to find your own charting solution.

I put some notes on my blog about Allegro and using it on the Mac.



回答10:

OpenGL?



回答11:

I would go for AGG or Cairo.