[GIL] read/write jpeg image from/to a buffer, not a file
Hi, Is it possible to read/write an image as JPEG from/into a memory buffer instead of a file? I found that reference which looks promising: https://stackoverflow.com/questions/16259659/read-a-jpeg-image-from-memory-w... but grep -r jpeg_tag in boost/gil gives nothing (same with image_read_settings) and read_image has no documentation and not the same signature. Anyone knows something about that? F
On 18 July 2018 at 15:05, Frédéric via Boost-users
Hi,
Is it possible to read/write an image as JPEG from/into a memory buffer instead of a file?
I found that reference which looks promising: https://stackoverflow.com/questions/16259659/read-a-jpeg-image-from-memory-w...
I've just submitted new answer to this SO question: https://stackoverflow.com/a/51525873/151641 Does it also address your question? Best regards, -- Mateusz Loskot, http://mateusz.loskot.net
Hi all, On Wed, Jul 25, 2018 at 2:56 PM Mateusz Loskot via Boost-users < boost-users@lists.boost.org> wrote:
On 18 July 2018 at 15:05, Frédéric via Boost-users
wrote: Hi,
Is it possible to read/write an image as JPEG from/into a memory buffer instead of a file?
I assume you mean using something like a stringstream as an in-memory buffer. The test suite has some examples, like: BOOST_AUTO_TEST_CASE( stream_test ) { // 1. Read an image. std::ifstream in( jpeg_filename.c_str(), ios::binary ); rgb8_image_t img; read_image( in, img, tag_t() ); // 2. Write image to in-memory buffer. std::stringstream out_buffer( ios_base::in | ios_base::out | ios_base::binary ); write_view( out_buffer, view( img ), tag_t() ); // 3. Copy in-memory buffer to another. std::stringstream in_buffer( ios_base::in | ios_base::out | ios_base::binary ); in_buffer << out_buffer.rdbuf(); // 4. Read in-memory buffer to gil image rgb8_image_t dst; read_image( in_buffer, dst, tag_t() ); // 5. Write out image. std::string filename( jpeg_out + "stream_test.jpg" ); std::ofstream out( filename.c_str(), ios_base::binary ); write_view( out, view( dst ), tag_t() ); } Does that help? Regards, Christian
I assume you mean using something like a stringstream as an in-memory buffer. The test suite has some examples
Does that help?
Yes, that's what I need. I just need to upgrade to 1.68 which I postponed: I'm sticked to 1.65.1 because of API changes in boost::asio in 1.66. So I guess, now I have no choice but upgrading! Thanks, F
I've just submitted new answer to this SO question: https://stackoverflow.com/a/51525873/151641
Does it also address your question?
Of course it does, that's exactly what I require. Thanks, F
participants (3)
-
Christian Henning
-
Frédéric
-
Mateusz Loskot