Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

image

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.

like image 848
mr.bio Avatar asked Feb 12 '10 22:02

mr.bio


People also ask

Can I use OpenCV with C?

OpenCV is a popular Computer Vision library to develop applications built using C++ and C. It has several uses like Object Detection and Video Processing. Computer Vision overlaps with fields like Image Processing, Photogrammetry, and Pattern Recognition. A popular wrapper Emgu CV is used to run OpenCV using C#.

What is photo type in C?

A digital C Type is any photographic print that has been exposed using digital technology, rather than traditional analogue (otherwise known as 'darkroom') techniques.


2 Answers

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:

  • SDL-Image
  • ImageMagick
  • Qt's QImageReader
  • wxWidgets
  • cImg (Which will try to read files if the appropriate filetype-specific library is available.)
  • Boost.GIL (Which, apparently, has support for JPEG, PNG, and TIFF files.)

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.

like image 185
greyfade Avatar answered Sep 20 '22 15:09

greyfade


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.

like image 30
bta Avatar answered Sep 22 '22 15:09

bta