Results 1 to 10 of 10

Thread: QImage and "raw" grey scale

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QImage and "raw" grey scale

    So, after simplifying even more this is my code:
    Qt Code:
    1. void convert16to8mono(QImage &qimage,unsigned short *inBuff, int sizeBytes, unsigned char *outBuff)
    2. {
    3. qimage.setNumColors(1);
    4. qimage.setColor(0,qRgb(255,0,0));
    5.  
    6. for(int y=0,i=0;y<960; y++)
    7. for(int x=0; x<1280; x++,i++)
    8. {
    9. qimage.setPixel(x,y,0);
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    and I use it like that:
    Qt Code:
    1. QPixmap pixmap(1280,960);
    2. QImage qimage(1280,960,QImage::Format_Indexed8);
    3. convert16to8mono(qimage,buff,size*2,buff8);
    4. if(!qimage.isNull())
    5. pixmap.fromImage(qimage);
    6.  
    7. ui.lblImage->setPixmap(pixmap);
    To copy to clipboard, switch view to plain text mode 

    result is a uniform gray image, instead of a red image....

    I am at a loss to what I still might be doing wrong...

    EDIT:
    I solved it.
    As always the problem ist between the chair and keyboard.
    I forgot that fromImage returns the new pixmap, and not changing the calling object.

    Thanks for helping.
    Last edited by high_flyer; 9th December 2008 at 17:00.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

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

    Default Re: QImage and "raw" grey scale

    Hi Dani,

    Ah... I think I see the problem. QPixmap::fromImage() is a static method returning a pixmap, thus it should be:
    Qt Code:
    1. QPixmap px = QPixmap::fromImage(qimage);
    To copy to clipboard, switch view to plain text mode 

    So the problem is not with the image, but with the pixmap you try to convert it to.

  3. The following user says thank you to wysota for this useful post:

    high_flyer (9th December 2008)

  4. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QImage and "raw" grey scale

    hehe - I just saw it by my self as you where posting your answer

    Thanks!
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

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
  •  
Qt is a trademark of The Qt Company.