Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Check if a QImage is empty
Forum Updated to NodeBB v4.3 + New Features

Check if a QImage is empty

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jerome96
    wrote on last edited by Jerome96
    #1

    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 :)

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      zaps166
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved