[SOLVED] Fastest method of chopping up an image?
So once again, I’m working on a level editor for a 2D tile-based game. The tiles are 32×32 pixels large and are all stored within a single 512×512 image (for a total of 256 tiles).
We have devised a method of splitting up the tiles that involves creating a QImageReader for the PNG file, extracting chunks of QImages, then converting those QImages to QPixMaps for rendering later… While it isn’t SUPER slow, it is still too unresponsive to not have some form of a loadbar for the user.
Is there any faster method of doing this? I’m not sure how QImageReader works, but I’m guessing there could be a chance that it’s literally reopening and closing the file for each fetch. Is there a way to grab the WHOLE IMAGE then read subsets of that QImage into other QImages?
Thanks for your time and help! Source code attached.
- unsigned spriteAmount = (sheetWidth/spriteWidth)*(sheetHeight/spriteHeight);
- unsigned int curRow = 0;
- unsigned int curColumn = 0;
- unsigned int rowSize = sheetWidth/spriteWidth;
- for(; clipRect.y() < sheetHeight; clipRect.translate (0,(clipRect.y() + (int)spriteHeight <= sheetHeight)? spriteHeight : sheetHeight-clipRect.y())) {
- for(clipRect.moveTo(0,clipRect.y()); clipRect.x() < sheetWidth; clipRect.translate((clipRect.x() + (int)spriteWidth <= sheetWidth)? spriteWidth : sheetWidth-clipRect.x(),0)) {
- reader.setClipRect(clipRect);
- if(image.isNull()) {
- Debug::Log(Debug::CRITICAL, "TileManager::DivideSpriteSheet(): There was an error reading the image! Error message: " + error);
- //sprite._spriteAmount = 0;
- return false;
- }
- if(curRow*rowSize+curColumn >= spriteAmount) return false;
- ++curColumn;
- }
- curColumn = 0;
- ++curRow;
- }
3 replies
You must log in to post a reply. Not a member yet? Register here!


