Boost logo

Boost Users :

Subject: Re: [Boost-users] [GIL] read/write jpeg image from/to a buffer, not a file
From: Christian Henning (chhenning_at_[hidden])
Date: 2018-07-25 19:14:02


Hi all,

On Wed, Jul 25, 2018 at 2:56 PM Mateusz Loskot via Boost-users <
boost-users_at_[hidden]> wrote:

> On 18 July 2018 at 15:05, Frédéric via Boost-users
> <boost-users_at_[hidden]> 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​



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net