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);
}
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);
}
To copy to clipboard, switch view to plain text mode
this is the LoadImage.
filename = f;
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;
}
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;
}
To copy to clipboard, switch view to plain text mode
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.
Bookmarks