void MainWindow::doF1()
{
tr
("Open Image"),
QDir::currentPath());
if (!fileName.isEmpty()) {
if (tempImage.isNull()) {
tr("Cannot load %1.").arg(fileName));
return;
}
QImage image
= tempImage.
convertToFormat(QImage::Format_RGB32);
RGBImage rgbImage;
rgbImage.resize(image.width(), image.height());
int pixel = 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);
unsigned char rcomp = (unsigned char)(qRed(pixel));
unsigned char gcomp = (unsigned char)(qGreen(pixel));
unsigned char bcomp = (unsigned char)(qBlue(pixel));
rgbImage.setPix(x, y, rcomp, gcomp, bcomp);
pixel = rgbImage(x,y);
image.setPixel(x, y, pixel);
}
}
graphicsViewVis->setScene(scene);
graphicsViewVis->show();
}
}
void MainWindow::doF1()
{
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;
}
QImage image = tempImage.convertToFormat(QImage::Format_RGB32);
RGBImage rgbImage;
rgbImage.resize(image.width(), image.height());
int pixel = 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);
unsigned char rcomp = (unsigned char)(qRed(pixel));
unsigned char gcomp = (unsigned char)(qGreen(pixel));
unsigned char bcomp = (unsigned char)(qBlue(pixel));
rgbImage.setPix(x, y, rcomp, gcomp, bcomp);
pixel = rgbImage(x,y);
image.setPixel(x, y, pixel);
}
}
QGraphicsScene *scene = new QGraphicsScene;
QGraphicsPixmapItem *item = scene->addPixmap(QPixmap::fromImage(image));
item->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
item->setFlag(QGraphicsItem::ItemIsMovable);
graphicsViewVis->setScene(scene);
graphicsViewVis->show();
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks