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.
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.
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.
来源:https://stackoverflow.com/questions/1924171/simple-c-graphics-library