Ticket #15 (closed defect: fixed)

Opened 20 months ago

Last modified 10 months ago

use streams to write image data

Reported by: nick@… Owned by: artem
Priority: Milestone: 0.5.0
Component: Core Library Version: SVN Trunk
Severity: Minor Keywords: stream i/o image
Cc: Patch Needs Improvement:
Needs Docmentation: Has Patch?:
Design Decision Needed:

Description

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<Image32> r(m,buf); r.apply(); save_to_file<ImageData?32>(pngfile,"png",buf.data());

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

output_to_stream<ImageData?32> (std::cout, "png", buf.data());

Change History

Changed 15 months ago by artem

  • component changed from Shapefile indexing to Core Library
  • milestone changed from 0.4.1 to 0.5.0

Changed 11 months ago by artem

  • status changed from new to assigned
  • summary changed from fixme to use streams to write image data

Changed 10 months ago by artem

  • keywords stream i/o image added
  • status changed from assigned to closed
  • resolution set to fixed

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 <iostream>
#include <fstream>
#include <sstream>

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;
}

Note: See TracTickets for help on using tickets.