How to cut an image into small (not rectangular shaped) parts?
Basically i want to make a little puzzle game, therefore i need to take an image and cut it into little puzzle parts.
Now the problem is i have no idea how to achieve this and need some hints into the right direction or ultimately a little code example.
thanks in advance
Calculate the rectangle of the little piece and then use "copy":http://qt-project.org/doc/qt-5.0/qtgui/qpixmap.html#copy
[quote author="Chris Kawa" date="1368906652"]Calculate the rectangle of the little piece and then use "copy":http://qt-project.org/doc/qt-5.0/qtgui/qpixmap.html#copy[/quote]
With copy i can only get rectangles (or am i missing something?), thats why i asked for a way to get custom shapes out of an image.
I want to split an image into shapes like this:
It's still a rectangle image. You just need to apply an alpha channel (transparency) to it.
Take a look at "setMask":http://qt-project.org/doc/qt-5.0/qtgui/qpixmap.html#setMask
You can use the image above for the mask, just need to invert the colors. Black is transparent, white opaque.
Yeah, the other solution would be to have the puzzle piece a vector shape with the image being implemented as a fill, but it will be harder to do compared to images.
First of all thanks for the answers.
When i think about using setMask im running into a difficulty in my brain. I guess its possible to do it with masks, but of course not every puzzle piece should look the same. In order to give them a "random" look (like the "nipple" more to the top or to the bottom of the piece or the hole more left/right etc.) i would need to use alot of different masks while making sure they are still compatible with eachother (to complete the puzzle in the end).
So is there maybe another way?
Just use a collection of images for different pieces. You can even write a function to generate the rectangle from the mask up left top and bottom maximum values and divide up your image into the right size bits with appropriate masks. I guess it will be a little more work to figure where each piece snaps into place, but certainly doable.
But I guess the best way to go is to actually randomly generate your puzzle pieces. Start with a square, and depending on its position in the entire puzzle just add 2-4 shapes to each end of the square, and naturally, reuse that same shape's negative for the pieces that are situated next.