Results 1 to 4 of 4

Thread: Accessing alpha channel of QImage directly

  1. #1
    Join Date
    Nov 2008
    Posts
    38
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Accessing alpha channel of QImage directly

    Hi. I'm trying to create a QImage and set the alpha channel to some value on a per-pixel basis. setAlphaChannel is no good because it sets the whole image at once.

    Ideally, I'd have brushes treat the alpha component as non-special, i.e. the operation wouldn't be
    pixel = (old_r,old_g,old_b)*(1-alpha) + (new_r,new_g,new_b)*alpha
    but instead
    pixel = (new_r, new_g, new_b, new_a)
    or even
    pixel = (old_r,old_g,old_b,old_a)*(1-beta) + (new_r,new_g,new_b,new_a)*beta

    In the short term, however, setting pixels' alphas individually would be acceptable.
    Last edited by spraff; 19th March 2009 at 15:40.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Initially transparent QImage

    And what is wrong with using QImage::setPixel()?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Nov 2008
    Posts
    38
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default

    setPixel refers to RGB, not RGBA

    Oh, and I forgot to say, the long term solution for me is to paint alpha channels directly via a brush, but this refers to QPainters and not QImages! I'm doing it per-pixel in a QImage at the moment as a short term hack

    Thinking about it, what I'm after is a kind of "eraser" brush, photoshop-style, and I want this to be at the level of a QBrush, not pixel hacking.
    Last edited by wysota; 19th March 2009 at 16:28.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Accessing alpha channel of QImage directly

    Quote Originally Posted by spraff View Post
    setPixel refers to RGB, not RGBA
    No, it referrs to QRgb which may also contain the alpha value.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. How to set Qt window transparent?
    By montylee in forum Qt Programming
    Replies: 17
    Last Post: 24th December 2013, 20:11
  2. Replies: 12
    Last Post: 7th September 2011, 16:37
  3. How can I create a transparent image with QImage?
    By learning_qt in forum Qt Programming
    Replies: 1
    Last Post: 28th January 2009, 15:06
  4. Multiple QPainters on QImage
    By fire in forum Qt Programming
    Replies: 3
    Last Post: 14th August 2008, 13:10
  5. leaveEvent on transparent area issue
    By nooky59 in forum Qt Programming
    Replies: 10
    Last Post: 8th January 2008, 13:22

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.