How to construct QImage from data in std::string format by save_to_string method?

160 views
Skip to first unread message

Jian Zhu

unread,
Jan 17, 2014, 2:59:38 PM1/17/14
to map...@googlegroups.com

Dear everyone,
Recently, I begin to learn to render street map using the data from http://www.openstreetmap.org/. I find that mapnik lib is really a useful and efficient tool to render maps. You are doing an excellent work.
But I come across a problem, I use metatile to improve my rendering performance. Like the following code:

//------------------------------------------Part of my code--------------------------------------------------------------------------------------------
image_32 buf(render_size_tx*TILE_WIDTH, render_size_ty*TILE_HEIGHT); //In general, render_size_tx = render_size_ty = 8
agg_renderer ren(metaMap,buf);

ren.apply();

unsigned int xx, yy;
for(xx = 0; xx < render_size_tx; xx++)
{
for(yy = 0; yy < render_size_ty; yy++)
{
image_view vw(xx*TILE_WIDTH, yy*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT, buf.data());
meta.setTile(xx, yy, save_to_string(vw, "png256"));

}

//------------------------------------------Part of my code--------------------------------------------------------------------------------------------

Each tile in the metatile is stored in std::string format. But what I need is QImage in QT, so how can I construct QImage from the std::string data? Is it like this
"QImage img((uchar* )(const_cast(meta.getTile(xx, yy).c_str())), TILE_WIDTH, TILE_HEIGHT, QImage::Format_ARGB32);" ? But in practice, it is wrong.
Can you give me some correct examples?

Thank you for your kind consideration.
Sincerely,
Jian Zhu

Dane Springmeyer

unread,
Jan 17, 2014, 4:41:02 PM1/17/14
to map...@googlegroups.com
One approach is to copy the image_view to a new image_32 or image_data_32 that is the same size.

And then you can call im.raw_data() to pass like the example at


For another case where we had to copy an image_view back to an newly sized image is for webp encoding:


Dane

--
You received this message because you are subscribed to the Google Groups "mapnik" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapnik+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Jian Zhu

unread,
Jan 18, 2014, 2:08:22 AM1/18/14
to map...@googlegroups.com
Dear Dane,
Thank you for your reply.
Yes, you are exactly right. We can copy the image_view to a new image_32 or image_data_32 that is the same size. But I am new to mapnik, can you give some examples? 

And I have another question,  in the code I offered, I add the following three line, then I will get building errors in vs2010. Can you tell me why? 

uchar* mybuf = (vw.data()).getBytes();
QImage img(mybuf,256,256,QImage::Format_ARGB32);
img.save("mytest.png");


zhan...@supermap.com

unread,
Nov 5, 2014, 9:12:28 AM11/5/14
to mapnik
Hi, Zhujiang 
 please post the error log ...
 I have build mapnik and the qt sample in VS2010, it seems that I can do something helpful...
 

Zhang Lili Ph.D 
SuperMap Software Co., Ltd. (Headquarters)
Address: 3/F Unit E, Building 201, No. A10, Jiuxianqiao North Road, Chaoyang District, Beijing, PR China, 100015
TEL: +86-10-5989 6655
FAX: +86-10-5989 6666
    
    E-Mail: zhan...@supermap.com
    Voice: +86-10-82736655   Fax: +86-10-82734630
Reply all
Reply to author
Forward
0 new messages