Results 1 to 3 of 3

Thread: Undisplay Image. Please Help

  1. #1
    Join Date
    Dec 2017
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Undisplay Image. Please Help

    Hi i have a project about image.
    This code is to load an image.
    Qt Code:
    1. void MainWindow::on_btnLoadImage_clicked()
    2. {
    3. QString fileName = QFileDialog::getOpenFileName(this, tr("Open Image"), "", tr("Image Files (*.png *.jpg *.bmp *.tif)"));
    4. img.LoadImage(fileName);
    5. renderArea->SetImage(&img);
    6.  
    7. }
    To copy to clipboard, switch view to plain text mode 

    this is the LoadImage.
    Qt Code:
    1. bool Image::LoadImage(QString f) {
    2. filename = f;
    3.  
    4. QImage img;
    5.  
    6. if (!img.load(f)) {
    7. return false;
    8. }
    9.  
    10. xDim = img.width();
    11. yDim = img.height();
    12. bitsPerPixel = img.bitPlaneCount();
    13. //pixels.setNum()
    14. for (int row=0; row<yDim; row++) {
    15. for (int col=0; col<xDim; col++) {
    16. QColor c = img.pixel(col,row);
    17. pixels.append(c.red());
    18. pixels.append(c.green());
    19. pixels.append(c.blue());
    20. cout<<"Loading ["<<col<<","<<row<<"] ("<<(int)c.red()<<","<<(int)c.green()<<","<<(int)c.blue()<<")"<<endl;
    21. }
    22. }
    23.  
    24. cout<<"Done loading"<<endl;
    25.  
    26. return true;
    27. }
    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.
    Last edited by high_flyer; 12th December 2017 at 17:19. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Undisplay Image. Please Help

    . 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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Undisplay Image. Please Help

    "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.

Similar Threads

  1. Replies: 15
    Last Post: 24th July 2015, 22:33
  2. Replies: 4
    Last Post: 15th May 2013, 13:58
  3. Replies: 3
    Last Post: 3rd August 2012, 10:35
  4. Replies: 3
    Last Post: 14th March 2007, 08:09

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.