Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use streams to write image data #15

Closed
artemp opened this issue Oct 11, 2011 · 3 comments
Closed

use streams to write image data #15

artemp opened this issue Oct 11, 2011 · 3 comments
Milestone

Comments

@artemp
Copy link
Member

artemp commented Oct 11, 2011

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
Copy link
Member Author

artemp commented Oct 11, 2011

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

{{{
#include <mapnik/image_data.hpp>
#include <mapnik/png_io.hpp>
#include <mapnik/graphics.hpp>

#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 as completed Oct 11, 2011
@chngl
Copy link

chngl commented Jan 13, 2012

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

@springmeyer
Copy link
Member

@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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants