void MainWindow::doF3()
{
tr
("Open Image"),
QDir::currentPath());
if (!fileName.isEmpty()) {
if (image.isNull()) {
tr("Cannot load %1.").arg(fileName));
return;
}
int pixel = 0;
int red = 0;
int green = 0;
int blue = 0;
int gray = 0;
int alpha = 0;
int x = 0;
int y = 0;
for (x = 0; x < image.width(); x++){
for (y = 0; y < image.height(); y++){
pixel = image.pixel(x, y);
red = qRed(pixel);
green = qGreen(pixel);
blue = qBlue(pixel);
gray = qGray(pixel);
alpha = qAlpha(pixel);
//This does not seem to create a grayscaled pixel
image.setPixel(x, y, qRgba(qRed(gray), qGreen(gray), qBlue(gray), alpha));
//Even this one does not seem to create a grayscaled pixel
//image.setPixel(x, y, qGray(red, green, blue));
}
}
graphicsViewVis->setScene(scene);
graphicsViewVis->show();
}
}
void MainWindow::doF3()
{
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open Image"), QDir::currentPath());
if (!fileName.isEmpty()) {
QImage image(fileName);
if (image.isNull()) {
QMessageBox::information(this, tr("Load Warning"),
tr("Cannot load %1.").arg(fileName));
return;
}
int pixel = 0;
int red = 0;
int green = 0;
int blue = 0;
int gray = 0;
int alpha = 0;
int x = 0;
int y = 0;
for (x = 0; x < image.width(); x++){
for (y = 0; y < image.height(); y++){
pixel = image.pixel(x, y);
red = qRed(pixel);
green = qGreen(pixel);
blue = qBlue(pixel);
gray = qGray(pixel);
alpha = qAlpha(pixel);
//This does not seem to create a grayscaled pixel
image.setPixel(x, y, qRgba(qRed(gray), qGreen(gray), qBlue(gray), alpha));
//Even this one does not seem to create a grayscaled pixel
//image.setPixel(x, y, qGray(red, green, blue));
}
}
QGraphicsScene *scene = new QGraphicsScene;
QGraphicsPixmapItem *item = scene->addPixmap(QPixmap::fromImage(image));
graphicsViewVis->setScene(scene);
graphicsViewVis->show();
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks