Results 1 to 6 of 6

Thread: How can I create a sprite sheet using qpixmap or qimage or whatever?

  1. #1
    Join Date
    Apr 2009
    Posts
    132
    Thanks
    67
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Smile How can I create a sprite sheet using qpixmap or qimage or whatever?

    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.

  2. #2
    Join Date
    Mar 2009
    Location
    Belchatow, Poland
    Posts
    38
    Thanks
    11
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: How can I create a sprite sheet using qpixmap or qimage or whatever?

    I think you want this: http://doc.trolltech.com/4.5/qimage.html#copy you can use it like this:

    Qt Code:
    1. QImage sheet("sheet.png");
    2. QImage sprite = sheet.copy(0, 0, 48, 48);
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to arturo182 for this useful post:

    ricardo (17th May 2009)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How can I create a sprite sheet using qpixmap or qimage or whatever?

    You can QPainter::drawPixmap() or QPainter::drawImage() an image onto another.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    ricardo (17th May 2009)

  6. #4
    Join Date
    Apr 2009
    Posts
    132
    Thanks
    67
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How can I create a sprite sheet using qpixmap or qimage or whatever?

    Quote Originally Posted by arturo182 View Post
    I think you want this: http://doc.trolltech.com/4.5/qimage.html#copy you can use it like this:

    Qt Code:
    1. QImage sheet("sheet.png");
    2. QImage sprite = sheet.copy(0, 0, 48, 48);
    To copy to clipboard, switch view to plain text mode 
    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?

  7. #5
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How can I create a sprite sheet using qpixmap or qimage or whatever?

    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

  8. The following user says thank you to talk2amulya for this useful post:

    ricardo (17th May 2009)

  9. #6
    Join Date
    Apr 2009
    Posts
    132
    Thanks
    67
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How can I create a sprite sheet using qpixmap or qimage or whatever?

    OK, I'll try it out.

    Thanks!

Similar Threads

  1. drawing on a QPixmap or QImage
    By gren15 in forum Newbie
    Replies: 15
    Last Post: 3rd March 2009, 17:48
  2. How can I create a transparent image with QImage?
    By learning_qt in forum Qt Programming
    Replies: 1
    Last Post: 28th January 2009, 15:06
  3. Construct QPixmap or QImage from raw data.
    By The Storm in forum Qt Programming
    Replies: 5
    Last Post: 1st December 2008, 08:21
  4. DIB to QImage or QPixmap
    By ^NyAw^ in forum Qt Programming
    Replies: 0
    Last Post: 8th August 2008, 20:18
  5. Diff between QImage, QPixmap, QPicture
    By nupul in forum Newbie
    Replies: 6
    Last Post: 30th April 2008, 02:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.