PDA

View Full Version : How can I create a sprite sheet using qpixmap or qimage or whatever?



ricardo
17th May 2009, 12:06
Hi dudes!

I have several small PNGs and I'd like to copy them into a new and large PNG, to create a sprite sheet (and a text file with coordinates...)

I've been reading QPixmap and QImage docs but I don't see any method like CopyThisImagePartToThisOneWithThisPosition()

Does anyone have any suggestion?

Thanks a lot for yout help.

arturo182
17th May 2009, 12:22
I think you want this: http://doc.trolltech.com/4.5/qimage.html#copy you can use it like this:


QImage sheet("sheet.png");
QImage sprite = sheet.copy(0, 0, 48, 48);

wysota
17th May 2009, 12:56
You can QPainter::drawPixmap() or QPainter::drawImage() an image onto another.

ricardo
17th May 2009, 14:00
I think you want this: http://doc.trolltech.com/4.5/qimage.html#copy you can use it like this:


QImage sheet("sheet.png");
QImage sprite = sheet.copy(0, 0, 48, 48);

I'd like just the opposite, something like:

-Create a large QImage
-Open a small PNG or QImage an copy it to a specific position on that big QImage

What you said is the opposite, is how to extract sprites from sprite sheet.

Any idea?

talk2amulya
17th May 2009, 15:19
wysota already answered your query..elaborating it a bit more..create a big pixmap of the size that can contain all other images..use drawPixmap of painter to draw the images to respective positions..u can always find size of each pixmap you have, thus you can find out where to draw the next image in the big pixmap..should be a pretty straightforward task

ricardo
17th May 2009, 20:02
OK, I'll try it out.

Thanks!