Simple C++ Graphics Library

戏子无情 提交于 2019-11-29 14:16:40
greyfade

Cairo is an exceptional library for this task. If you're thinking it's overkill, I can reassure you that it most definitely is not a bloated or large library. Cairo is meant exactly for what you need it. Note that if you need the ability to set text on the image, you'll need a typesetting library such as Pango (which works well with it).

That said, most of the other libraries in this category are intended for games (like Allegro), or are limited to bitmap manipulations (like libGd and ImageMagick). Cairo was designed for application-generated vector images.

The CImg library is easy to use, allows to write concise code, and is defined in a single header file. Multiple examples are given.

Dirk Eddelbuettel

Qt does images including gradients etc, is portable, uses C++ and has rather decent documentation with a gazillion examples. It is however not the smallest library, but I have been quite happy with it.

Juce might do what you want. It can draw an image and fill areas with gradients and supports Windows, Linux and the Mac. Without more specific info, can't help any more than that.

Have you tried:

Corona

http://corona.sourceforge.net/

If you don't need dithering, just fill up your RGB frame buffer and pass it to Corona for output. If you need dithering, or conversion of bit depth, you're out of luck.

You should review its security and also the patch level of its included C libraries as the Corona seems to have been last updated many years ago, but its basically a fairly thin C++ layer on top of C libraries for GIF, JPEG and PNG with native BMP and PCX support.

I usually use the gd library, the same library used by php (among others), usually to create CAPTCHAs. But you can basically do anything you want with it.

Anti-Grain Geometry more samples.

I happened to have the similar requirement as you: I want to draw some basic 2D shapes and want the transparent feature when some shapes overlaps.

After I read the document of Cairo, I found that there are quite a lot concepts to remember. Hence I did my own search and found PNGwriter. Although it is a bit outdated that I have to modify the source code a little bit to make it compile with libpng1.4, the syntax is very intuitive and is exactly what I want. For example, you draw a filled rectangle with pngwritter::filledcircle.

Have a look at its example of plotting a math function:

http://pngwriter.sourceforge.net/quickstart-en.php

#include <pngwriter.h>


int main()
{
   int i;
   int y;

   pngwriter png(300,300,0,"test.png");

   for(i = 1; i < 300;i++)
     {
        y = 150+100*sin((double)i*9/300.0);

        png.plot(i,y, 0.0, 0.0, 1.0);
     }

   png.close();

   return 0;
}

The result is:

Mac OS X 10.6.7 ships with freetype and libpng, all you have to do it to update the source according to the compilation error, just some quick hacks.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!