Check if a QImage is empty



  • Hey guys

    I am programming kind of a tileset creator for my 2D game. So I want to add a new picture from my hard disk which is bigger than the actual tilesize, then split it up into tiles.
    I got that thing working, but when I use an image, it can happen that I have some tiles which are fully empty (because I didn't draw something on this part of the picture but can't leave this part away).

    So I asked my self, how is it possible to check if a QImage is completly empty? So every pixel of it is transparent?

    I hope you can help me.
    Thank you anyway :)



  • This can help for little-endian CPUs and "QImage::Format_ARGB32":

    quint32 *pixels = (quint32 *)img.bits();
    int imgSize = img.width() * img.height();
    bool isTransparent = true;
    for (int i = 0; i < imgSize; ++i)
    {
    	if (((pixels[i] >> 24) & 0xFF) != 0)
    	{
    		isTransparent = false;
    		break;
    	}
    }
    

    It checks that pixel is 100% transparent or not.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.