tags:

views:

269

answers:

6

Hi there ,

i am more a java developer and there is a standard way of reading images :

    BufferedImage img = null;
try {
    img = ImageIO.read(new File("strawberry.png"));
} catch (IOException e) {
}

but what is the c++ way of loading images?
I want to load all images in a specific directory into an array or so

Can somebody help ?

+1  A: 

The library you will want to use to load images will depend on what you intend to do with it. If you are using a framework such as QT or wxWidgets, it will provide image loading routines.

Another possibility is to use the the SDL Image library, and to work on SDL surfaces, which will allow you to work down to the pixel level if you need.

small_duck
+1  A: 

Take a look at DevIL

Axel Gneiting
+5  A: 

I personally prefer the ImageMagick library.

There are many available graphics processing libraries and there is not a single choice that stands out as clearly superior to the others. My advice it to make a short list of 3 or 4, take a look at the documentation for each, and try to write a simple half-page program with each. Use whichever one you personally find easiest to use.

bta
+4  A: 

There is no standard "way" in C++ to load images or files of any other sort. That feature is provided by (usually third-party) libraries.

On Windows, you can use the GDI or DirectX APIs to load images to memory.

You can also use any of many different libraries. Some that come to mind:

There are many, many others to look at, and some may be more appropriate than others depending on what you're trying to do.

For example, if you're only going to be working with JPEG files, then you'll want to use libIJG. Or if you'll only be using PNG, you might find libPNG or cairo to be more appropriate.

greyfade
+1  A: 

Qt has good support for images, and is free and cross-platform.

Check out the qimage class

Graphics Noob
A: 

I would say that the closest you'll get to a standard way of doing this is with the Boost/Adobe Generic Image Library.

Manuel