PDA

View Full Version : Painter greyscale, image quality paint-brush!



patrik08
22nd March 2007, 20:42
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?



#include <QApplication>
#include <QtGui>
#include <QtCore>
#include <QCoreApplication>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel *label = new QLabel("Hello Picasso");
QPixmap bw = QPixmap("test.png","",Qt::MonoOnly);

QImage base0("test.png");
QImage base = base0.convertToFormat(QImage::Format_MonoLSB,Qt::M onoOnly);
/////QPixmap display;
QPixmap xnew(base.width(),base.height());
xnew.fill();

/* paint B/W */
QPainter painter;
painter.begin(&xnew);
////// painter.setRenderHint(QPainter::Antialiasing);
painter.drawImage(0,0,QImage("test.png"));
painter.drawImage(base.width() / 2,0,base);
painter.end();

label->setPixmap(xnew);
label->show();
return app.exec();
}

jacek
22nd March 2007, 20:57
Qt::MonoOnly and QImage::Format_MonoLSB are for black & white pictures (i.e. with exactly two colours), not grayscale ones.

patrik08
22nd March 2007, 21:01
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); ?

jacek
22nd March 2007, 21:06
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.



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().

patrik08
22nd March 2007, 21:32
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.




#include <QtGui>
#include <QtCore>
#include <QCoreApplication>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel *label = new QLabel("Hello Picasso");
QPixmap bw = QPixmap("test.png");

QImage base0("test.png");
QImage base = base0.convertToFormat(QImage::Format_RGB32);

for (int y = 0; y < base.height(); ++y) {
for (int x = 0; x < base.width(); ++x) {
int pixel = base.pixel(x, y);
int gray = qGray(pixel);
int alpha = qAlpha(pixel);
base.setPixel(x, y, qRgba(gray, gray, gray, alpha));
}
}
QPixmap xnew(base.width(),base.height());
xnew.fill();

/* paint B/W */
QPainter painter;
painter.begin(&xnew);
painter.setRenderHint(QPainter::Antialiasing);
painter.drawImage(0,0,QImage("test.png"));
painter.drawImage(base.width() / 2,0,base);
painter.end();

label->setPixmap(xnew);
label->show();
return app.exec();
}