To install, just install the libfreeimage-dev package, either through Synaptic or using:
sudo apt-get install libfreeimage-devOnce you've got that installed, you can link to it from your C/C++ programs.
Here's some simple code to output a blue background to a bitmap:
#include <FreeImage.h>Then to compile:
#include <stdlib.h>
int main(){
FreeImage_Initialise();
atexit(FreeImage_DeInitialise);
// create the bitmap object
FIBITMAP * bitmap = FreeImage_Allocate(200, 200, 32); // allocate a 200x200 pixel image, with 32-bit colour
// create the blue colour
RGBQUAD blue;
blue.rgbBlue = 255;
for (int i = 0; i < 200; i++){
for (int j = 0; j < 200; j++){
// draw a blue pixel at (i, j)
FreeImage_SetPixelColor(bitmap, i, j, &blue);
}
}
// save it as output.bmp
FreeImage_Save(FIF_BMP, bitmap, "output.bmp");
// deallocate memory
FreeImage_Unload(bitmap);
}
g++ image.cpp -o image -lfreeimage
1 comment:
Thank you soo much for this tutorial.
It just worked as a charm!
Post a Comment