Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

use streams to write image data #15

Closed
artemp opened this Issue · 3 comments

3 participants

@artemp
Owner

It would be good to be able to output the raw data of a map image to a given output stream in the same way that you can output to file. For example:

Image32 buf(m.getWidth(),m.getHeight());
agg_renderer r(m,buf);
r.apply();
save_to_file(pngfile,"png",buf.data());

As well as save_to_file, have an output_to_stream function such as:

output_to_stream (std::cout, "png", buf.data());

@artemp
Owner

[artem] Image data can be saved to any STL style stream. Other objects (buffers) can be easily adapted.

{{{
#include
#include
#include

#include
#include
#include

int main(int argc, char** argv)
{
using namespace mapnik;
// create image and fill with colour
Image32 img(800,800);
img.setBackground(Color(0,0,255));

// save to file stream
std::ofstream file("test.png", std::ios::out| std::ios::trunc|std::ios::binary);
if (file)
{
save_as_png(file,img.data());
}
// save to string stream
std::ostringstream ss(std::ios::out|std::ios::binary);
save_as_png(ss,img.data());
std::cout << "buffer size = " << ss.str().size() << "\n";

return EXIT_SUCCESS;
}

}}}

@artemp artemp closed this
@chngl

Does python api have the similar function that can write the raw data to stream??
Thanks a lot

@springmeyer
Owner

@felix-1128 - the http://mapnik.org/contact/ is the right place for support requests, not closed tickets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.