(If you can't see the navitagion frame at the left of the page, then click here).

This is the most basic example of how to use PNGwriter. After you've had a look at this page, see the other examples. Here is the code and the image that is generated.

All functions can take two types of colour coefficients: either ints from 0 to 65535 or a doubles that go from 0.0 to 1.0 (as of version 0.3.2).

#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; }
An image

The constructor takes as arguments the width and the height (in pixels) of the image, the background colour (limited to a shade of grey, but that is fine since one usually just wants a black or white image to start with), and the filename.

To plot, use the plot function.

It takes, as arguments, the horizontal coordinate of the pixel (from 1 to the width),
the vertical coordinate of the pixel (from 1 to the height),
the coefficient of red (a double from 0.0 to 1.0),
the coefficient of green (a double from 0.0 to 1.0)
and the coefficient of blue (a double from 0.0 to 1.0).

Valid CSS!

© 2002, 2003, 2004, 2005, 2006, 2007 Paul Blackburn