implemented Image open method :
im = Image.open("map.png")
This commit is contained in:
parent
b54aa9091b
commit
1625c760db
1 changed files with 20 additions and 1 deletions
|
@ -35,9 +35,13 @@ extern "C"
|
|||
#include <mapnik/image_util.hpp>
|
||||
#include <mapnik/jpeg_io.hpp>
|
||||
#include <mapnik/png_io.hpp>
|
||||
#include <mapnik/image_reader.hpp>
|
||||
#include <sstream>
|
||||
|
||||
using mapnik::Image32;
|
||||
using mapnik::ImageReader;
|
||||
using mapnik::get_image_reader;
|
||||
using mapnik::type_from_filename;
|
||||
using namespace boost::python;
|
||||
using mapnik::save_to_file;
|
||||
|
||||
|
@ -62,6 +66,18 @@ PyObject* tostring2(Image32 const & im, std::string const& format)
|
|||
void (*save_to_file1)( mapnik::Image32 const&, std::string const&,std::string const&) = mapnik::save_to_file;
|
||||
void (*save_to_file2)( mapnik::Image32 const&, std::string const&) = mapnik::save_to_file;
|
||||
|
||||
boost::shared_ptr<Image32> open_from_file(std::string const& filename)
|
||||
{
|
||||
std::auto_ptr<ImageReader> reader(get_image_reader(filename,type_from_filename(filename)));
|
||||
if (reader.get())
|
||||
{
|
||||
boost::shared_ptr<Image32> image_ptr(new Image32(reader->width(),reader->height()));
|
||||
reader->read(0,0,image_ptr->data());
|
||||
return image_ptr;
|
||||
}
|
||||
throw mapnik::ImageReaderException("FIXME: " + filename);
|
||||
}
|
||||
|
||||
void blend (Image32 & im, unsigned x, unsigned y, Image32 const& im2, float opacity)
|
||||
{
|
||||
im.set_rectangle_alpha2(im2.data(),x,y,opacity);
|
||||
|
@ -70,7 +86,7 @@ void blend (Image32 & im, unsigned x, unsigned y, Image32 const& im2, float opac
|
|||
void export_image()
|
||||
{
|
||||
using namespace boost::python;
|
||||
class_<Image32>("Image","This class represents a 32 bit RGBA image.",init<int,int>())
|
||||
class_<Image32,boost::shared_ptr<Image32> >("Image","This class represents a 32 bit RGBA image.",init<int,int>())
|
||||
.def("width",&Image32::width)
|
||||
.def("height",&Image32::height)
|
||||
.def("view",&Image32::get_view)
|
||||
|
@ -82,5 +98,8 @@ void export_image()
|
|||
.def("tostring",&tostring2)
|
||||
.def("save", save_to_file1)
|
||||
.def("save", save_to_file2)
|
||||
.def("open",open_from_file)
|
||||
.staticmethod("open")
|
||||
;
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue