void MainWindow::doF3()
{
tr
("Open Image"),
QDir::currentPath());
if (!fileName.isEmpty()) {
if (tempImage.isNull()) {
tr("Cannot load %1.").arg(fileName));
return;
}
//loadedImage is a globally declared variable
loadedImage = tempImage;
//Here is one problem, I do not know what appropriate conversions I will do for reading JPEG PNG BMP
QImage image
= tempImage.
convertToFormat(QImage::Format_ARGB32_Premultiplied);
int pixel = 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);
gray = qGray(pixel);
alpha = qAlpha(pixel);
//Here is another problem, I do not know how to test if this makes the pixel grayscaled
image.setPixel(x, y, qRgba(qRed(gray), qGreen(gray), qBlue(gray), alpha));
}
}
//add the scene with grayscaled image to the right QGraphicsView
graphicsViewVis->setScene(scene);
graphicsViewVis->show();
}
}
void MainWindow::doF3()
{
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open Image"), QDir::currentPath());
if (!fileName.isEmpty()) {
QImage tempImage(fileName);
if (tempImage.isNull()) {
QMessageBox::information(this, tr("Load Warning"),
tr("Cannot load %1.").arg(fileName));
return;
}
//loadedImage is a globally declared variable
loadedImage = tempImage;
//Here is one problem, I do not know what appropriate conversions I will do for reading JPEG PNG BMP
QImage image = tempImage.convertToFormat(QImage::Format_ARGB32_Premultiplied);
int pixel = 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);
gray = qGray(pixel);
alpha = qAlpha(pixel);
//Here is another problem, I do not know how to test if this makes the pixel grayscaled
image.setPixel(x, y, qRgba(qRed(gray), qGreen(gray), qBlue(gray), alpha));
}
}
QGraphicsScene *scene = new QGraphicsScene;
//add the scene with grayscaled image to the right QGraphicsView
graphicsViewVis->setScene(scene);
graphicsViewVis->show();
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks