views:

463

answers:

7

Any suggestions for a simple C++ library I can use to create an image to a specified size, with either a fixed rgb colour value or ideally supporting gradients.

Needs to work on Windows and ideally but not required to work on OS X as well.

I've found Cairo, but just wondered if there was anything else as it seems quite simple what I require.

+1  A: 

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.

Chinmay Kanchi
Juce doesn't look "simple." It looks like a rather large library that does a lot of things that are completely unrelated the Adam's needs.
greyfade
+4  A: 

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.

greyfade
+1 on that. I used it in my own PhD code and it was a pleasure to work with. I used the libgtkmm (c++) version, though.
Diego Sevilla
+1  A: 

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.

martinr
+2  A: 

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.

Dirk Eddelbuettel
It's not simple and lightweight.
the_drow
As an installation, sure. But you only build against the components you need. So for a graphics app no xml, networking, sql, ... which one could still use for other apps. It matches a few of the requirements in the original question -- and he only asked for 'simple' but not for leightweight.
Dirk Eddelbuettel
+1  A: 

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.

Andreas Bonini
+1  A: 

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

rafak
A: 

Anti-Grain Geometry more samples.

alexey