How to install and use FreeImage

FreeImage is a simple library that can be used for reading and writing image files. If you have to read and write BMP, JPG or PNG files, then this is one of the easiest ways to do that. It has APIs available in C, C++ and .Net.

Install

Installing FreeImage on Ubuntu is easy:

$ sudo apt-get install libfreeimage3 libfreeimage-dev

Use

For C++ code, you can use the FreeImagePlus API, which is a C++ wrapper around the C API. Here is a simple example that reads a PNG image using the fipImage class:

#include <iostream>
#include <FreeImagePlus.h>

int main()
{
    fipImage img;
    img.load("foobar.png");

    std::cout << img.getWidth() << " " << img.getHeight() << std::endl;
    std::cout << img.isGrayscale() << std::endl;
    std::cout << img.getBitsPerPixel() << std::endl;

    return 0;
}

To compile code that uses the FreeImagePlus API, link it with libfreeimageplus.so using the directive -lfreeimageplus.

Tried with: FreeImage 3.15.1-1 and Ubuntu 12.04 LTS

Advertisements

One thought on “How to install and use FreeImage

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.