PDA

View Full Version : Undisplay Image. Please Help



truongphan
12th December 2017, 15:31
Hi i have a project about image.
This code is to load an image.

void MainWindow::on_btnLoadImage_clicked()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Open Image"), "", tr("Image Files (*.png *.jpg *.bmp *.tif)"));
img.LoadImage(fileName);
renderArea->SetImage(&img);

}

this is the LoadImage.

bool Image::LoadImage(QString f) {
filename = f;

QImage img;

if (!img.load(f)) {
return false;
}

xDim = img.width();
yDim = img.height();
bitsPerPixel = img.bitPlaneCount();
//pixels.setNum()
for (int row=0; row<yDim; row++) {
for (int col=0; col<xDim; col++) {
QColor c = img.pixel(col,row);
pixels.append(c.red());
pixels.append(c.green());
pixels.append(c.blue());
cout<<"Loading ["<<col<<","<<row<<"] ("<<(int)c.red()<<","<<(int)c.green()<<","<<(int)c.blue()<<")"<<endl;
}
}

cout<<"Done loading"<<endl;

return true;
}
now i want to create a Close button. Clicking this button should close the open image by un-displaying it from the screen, and freeing the
memory used to store the image. I am just beginner and i have no idea about this one .
thank you.

high_flyer
12th December 2017, 17:20
. I am just beginner and i have no idea about this one .
Well, you will need SOME idea.
Share what you did try and what didn't work, we will help you with the problems, but don't expect us to solve your home work for you.

ChrisW67
12th December 2017, 20:29
"Undisplayiog" is the same as drawing a "blank" image over the already displayed image.
Freeing the memory used to store the image could mean a number of things. The memory used to actually display the image is managed by Qt. The memory occupied by the "pixels" object is entirely under your control. We don't know, but it looks like "pixels" might be a QList/QVector or the like: both have functions to clear the data structure.