4

So I see samples all around on saving into file. But I wonder if it is possible to save into char* or string instead of file - so to say keep it in memory?

Rella
  • 65,003
  • 109
  • 363
  • 636
  • 1
    So you mean a raw memory buffer, representing a JPEG or PNG encoded image? – Christian Rau Nov 07 '11 at 16:21
  • @Christian Rau: a raw memory buffer, with a JPEG or PNG encoded image in it – Rella Nov 07 '11 at 16:31
  • GIL has ways to make copies of images already in memory ( http://www.boost.org/doc/libs/1_47_0/libs/gil/doc/html/giltutorial.html#InterfaceSec , difference between images and image views). What do you expect to get out of making different copy of in-memory stuff to a bag of bytes that's also in memory? – Max Lybbert Nov 07 '11 at 19:17
  • 2
    @Max Lybbert - You could, as an example, use it to generate PNG byte streams over HTTP for generating images on the fly without writing to disk. – clstrfsck Nov 07 '11 at 20:04
  • @Max Lybbert: Generally I want to do what `msandiford` proposed=) – Rella Nov 08 '11 at 02:08

2 Answers2

7

There doesn't seem to be anything to facilitate this in boost itself. All I/O seems to be based on supplying filenames.

However, there seems to be an extension here called io_new that has streams based I/O.

See documentation here for an example (search for "Reading And Writing In-Memory Buffers").

clstrfsck
  • 14,715
  • 4
  • 44
  • 59
  • I can confirm that this is not possible in the boost mainline release. I ended up pulling in ImageMagick but it was heavier than I expected. `io_new` or just straight `libpng` is a cleaner solution – totowtwo Nov 08 '11 at 13:41
  • 1
    Note that the author of `io_new` is in fact the maintainer of Boost.GIL, so the quality of the code is bound to be high (and he posted on the Boost ML last month requesting to merge `io_new` into mainline Boost; not sure how that's going). – ildjarn Nov 09 '11 at 22:33
1

Boost.GIL v1.75: reading this docs at the section "Reading And Writing In-Memory Buffers" seems boost::gil::write_view(...) can also write into a memory buffer. Please see also this question

albezanc
  • 25
  • 7