Results 1 to 5 of 5

Thread: Painter greyscale, image quality paint-brush!

  1. #1
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Painter greyscale, image quality paint-brush!

    I am not the best paint-brush !

    to make a color picture to greyscale i make so.

    Is here a other mode to grab moore quality?

    Qt Code:
    1. #include <QApplication>
    2. #include <QtGui>
    3. #include <QtCore>
    4. #include <QCoreApplication>
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication app(argc, argv);
    9. QLabel *label = new QLabel("Hello Picasso");
    10. QPixmap bw = QPixmap("test.png","",Qt::MonoOnly);
    11.  
    12. QImage base0("test.png");
    13. QImage base = base0.convertToFormat(QImage::Format_MonoLSB,Qt::MonoOnly);
    14. /////QPixmap display;
    15. QPixmap xnew(base.width(),base.height());
    16. xnew.fill();
    17.  
    18. /* paint B/W */
    19. QPainter painter;
    20. painter.begin(&xnew);
    21. ////// painter.setRenderHint(QPainter::Antialiasing);
    22. painter.drawImage(0,0,QImage("test.png"));
    23. painter.drawImage(base.width() / 2,0,base);
    24. painter.end();
    25.  
    26. label->setPixmap(xnew);
    27. label->show();
    28. return app.exec();
    29. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Painter greyscale, image quality paint-brush!

    Qt::MonoOnly and QImage::Format_MonoLSB are for black & white pictures (i.e. with exactly two colours), not grayscale ones.

  3. #3
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Painter greyscale, image quality paint-brush!

    Quote Originally Posted by jacek View Post
    Qt::MonoOnly and QImage::Format_MonoLSB are for black & white pictures (i.e. with exactly two colours), not grayscale ones.
    to build 256 level greyscale i must iterate each pixel?
    or only so...
    QImage base = base0.convertToFormat(QImage::Format_MonoLSB); ?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Painter greyscale, image quality paint-brush!

    Quote Originally Posted by patrik08 View Post
    to build 256 level greyscale i must iterate each pixel?
    If you had an image with a colour table, you would have to go only through the colour table.

    Quote Originally Posted by patrik08 View Post
    or only so...
    QImage base = base0.convertToFormat(QImage::Format_MonoLSB); ?
    QImage::Format_MonoLSB isn't the best choice, as it uses only 1 bit per pixel. Better try QImage::Format_Indexed8 and convert the colour table using qGray().

  5. The following user says thank you to jacek for this useful post:

    patrik08 (22nd March 2007)

  6. #5
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Painter greyscale, image quality paint-brush!

    Quote Originally Posted by jacek View Post
    If QImage::Format_MonoLSB isn't the best choice, as it uses only 1 bit per pixel. Better try QImage::Format_Indexed8 and convert the colour table using qGray().
    super i found on assistant Plug & Paint Basic Tools Example

    tools/plugandpaintplugins/basictools/basictoolsplugin.h

    the day will arrive that assistant speaks.


    Qt Code:
    1. #include <QtGui>
    2. #include <QtCore>
    3. #include <QCoreApplication>
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication app(argc, argv);
    8. QLabel *label = new QLabel("Hello Picasso");
    9. QPixmap bw = QPixmap("test.png");
    10.  
    11. QImage base0("test.png");
    12. QImage base = base0.convertToFormat(QImage::Format_RGB32);
    13.  
    14. for (int y = 0; y < base.height(); ++y) {
    15. for (int x = 0; x < base.width(); ++x) {
    16. int pixel = base.pixel(x, y);
    17. int gray = qGray(pixel);
    18. int alpha = qAlpha(pixel);
    19. base.setPixel(x, y, qRgba(gray, gray, gray, alpha));
    20. }
    21. }
    22. QPixmap xnew(base.width(),base.height());
    23. xnew.fill();
    24.  
    25. /* paint B/W */
    26. QPainter painter;
    27. painter.begin(&xnew);
    28. painter.setRenderHint(QPainter::Antialiasing);
    29. painter.drawImage(0,0,QImage("test.png"));
    30. painter.drawImage(base.width() / 2,0,base);
    31. painter.end();
    32.  
    33. label->setPixmap(xnew);
    34. label->show();
    35. return app.exec();
    36. }
    To copy to clipboard, switch view to plain text mode 

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.