Search code examples
c++imageboostboost-gil

Read image and access bytes in boost::gil


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.


Solution

  • 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..