Read image and access bytes in boost::gil

2.3k views Asked by At

Is it possible to:

  • read an image given by just a filename (not knowing the image format) to a 2d matrix rgb uncompressed form (e.g. read an JPG to a 2d array)
  • access the bytes of that image, copy them, change them... (e.g. inverse the colors, I need a pointer to the image bytes, setters/getters won't do )
  • save those bytes to any given image format (e.g. save the inversed image to PNG)

Is it possible with boost::gil ? Maybe there is a different library more appropriate for such a task?

Sample code would be highly appreciated.

2

There are 2 answers

0
emesx On BEST ANSWER

Yes, you can do all that in boost::gil. What you should know though, is that boost::gil is only a universal interface and doesn't handle reading/writing images all by itself. You still need to use a second library, e.g. libpng..

5
Mark Garcia On

Yes, yes and yes.

There are functions that enable you to read and write JPEG, TIFF and PNG images: see here.

For the second bullet, it is what just GIL is meant to do. You can manipulate images using its facilities (click here).