mr.bio
mr.bio

Reputation: 1686

How can I read/load images in C++?

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.

Upvotes: 10

Views: 15237

Answers (6)

bta
bta

Reputation: 45057

Personally, I 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 is 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.

Upvotes: 9

greyfade
greyfade

Reputation: 25647

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.

Upvotes: 8

Manuel
Manuel

Reputation: 13109

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

Upvotes: 1

Graphics Noob
Graphics Noob

Reputation: 10050

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

Check out the qimage class

Upvotes: 1

Axel Gneiting
Axel Gneiting

Reputation: 5403

Take a look at DevIL

Upvotes: 1

small_duck
small_duck

Reputation: 3094

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.

Upvotes: 1

Related Questions