On Jul 17, 2010, at 12:22 PM, Jon Burgess wrote:
> On Sat, 2010-07-17 at 12:35 +0800, feverzsj wrote:
>> hi, list:
>> some python code:
>> im = mapnik.Image(self.map.width, self.map.height)
>> mapnik.render(self.map, im)
>> qim = QImage()
>> qim.loadFromData(QByteArray(im.tostring('png')))
>>
>> The questions are: why we should pass a string 'png'? What is stored
>> in mapnik.Image? What is done in the tostring()?
>
> The mapnik.Image is a wrapper around the raw bitmap data of the rendered
> image. The tosting('png') asks mapnik to convert this into a PNG image
> and return it as a python string. This is then converted into a QT byte
> array and then finally converted into a QImage.
>
> A PNG image was probably chosen as a simple standard format which Mapnik
> can create and QT can read. This method is fairly simple and reliable
> but not the most efficient.
>
> It may be possible to directly convert the raw bitmap data from Mapnik
> into a QImage but it would need some careful reading of the docs to
> figure out if they are compatible. This approach is taken by the C++
> Mapnik viewer application:
> http://trac.mapnik.org/browser/trunk/demo/viewer/mapwidget.cpp#L460
>
Nice spot Jon!
This seems to work:
instead of:
self.qim.loadFromData(QByteArray(im.tostring('png')))
do:
self.qim = QImage(im.tostring(),self.map.width,
self.map.height,QImage.Format_ARGB32).rgbSwapped()
> Jon
>
>
> _______________________________________________
> Mapnik-users mailing list
> [email protected]
> https://lists.berlios.de/mailman/listinfo/mapnik-users
_______________________________________________
Mapnik-users mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/mapnik-users