Results 1 to 4 of 4

Thread: alpha for pixel always returns 255

  1. #1
    Join Date
    Mar 2016
    Posts
    6
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default alpha for pixel always returns 255

    In this code alpha is always 255 even thought the box displays in my QLabel with a transparency. Can anyone tell me why alpha is always 255?

    QImage img;
    img.load(":/images/images/box.png");
    QColor rgba( img.pixel( 1, 1) );
    qDebug() << " r: "<<rgba.red()<<" g: "<<rgba.green()<<" b: "<<rgba.blue()<<" a: "<<rgba.alpha() << endl;
    qDebug() << pixmap.hasAlpha() << " : " << pixmap.hasAlphaChannel() << endl;

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: alpha for pixel always returns 255

    What does img.format() return? What is the output of your qDebug() statements? And where does "pixmap" come from?

    Posting your actual code would be better than posting something that won't even compile.

  3. #3
    Join Date
    Mar 2016
    Posts
    6
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: alpha for pixel always returns 255

    img.format() returns QImage::Format_ARGB32

    Sorry about not including the pixmap. I was trying to snip out the relevant section of code and forgot to clip that line. It was just sourcing the box.png in a different way and can be ignored. The box.png image is an uniform image and has an alpha of 128. The output is
    r: 0 g: 128 b: 255 a: 255

    I found the problem though. It appears the QColor constructor doesn't use the alpha values, at least according to this thread.
    http://www.qtforum.org/article/32132...-a-qimage.html

    thanks.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: alpha for pixel always returns 255

    It appears the QColor constructor doesn't use the alpha values
    Ah, yes, forgot about that. You could use the QColor( int r, int g, int b, int a ) constructor instead, by extracting the relevant values from the QRgb returned from QImage::pixel().

Similar Threads

  1. Replies: 0
    Last Post: 1st February 2014, 17:35
  2. Filling a pie pixel by pixel
    By pradhan in forum Qt Programming
    Replies: 1
    Last Post: 10th December 2013, 09:33
  3. Replies: 2
    Last Post: 17th February 2012, 00:10
  4. QPixmap pixel by pixel ?
    By tommy in forum Qt Programming
    Replies: 19
    Last Post: 3rd December 2007, 23:52
  5. image alpha
    By murko81 in forum Qt Programming
    Replies: 13
    Last Post: 28th October 2006, 20:31

Tags for this Thread

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.