Results 1 to 3 of 3

Thread: Take a Screenshot on Android

  1. #1
    Join Date
    Oct 2014
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Take a Screenshot on Android

    Hi, all!

    I have an application - shapes viewer. My app consists of two main components. There are OpenGL Viewer and Qt/Qml toolbar. I am trying to take screenshot of my app.

    First time I have tried this one:
    Qt Code:
    1. QQuickWindow* window = this->window();
    2. if (window)
    3. {
    4. QImage image = window->grabWindow();
    5. image.save(QString(path)); // The path is valid
    6. }
    To copy to clipboard, switch view to plain text mode 

    At the first launch of the app the screenshot was taken properly, but app was frozen. On the next launches app was freezing without taking screenshot. The app is freezing when I am calling
    Qt Code:
    1. QImage image = window->grabWindow();
    To copy to clipboard, switch view to plain text mode 

    Also, I have tried, but it is doesn't work:
    Qt Code:
    1. QScreen *screen = QGuiApplication::primaryScreen();
    2. if(screen)
    3. {
    4. QPixmap originalPixmap = screen->grabWindow(this->window()->winId());
    5. if(originalPixmap.save(QString(path)))
    6. {
    7. qDebug() << QString("Screenshot saved");
    8. }
    9. else
    10. {
    11. qDebug() << QString("Screenshot not saved");
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    Please, help to solve this problem

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Take a Screenshot on Android

    Why don't you just render the window to an FBO and convert the result to image?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2014
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Take a Screenshot on Android

    I am new at Qt and didn't know about rendering windows to an FBO.

    I tried:
    Qt Code:
    1. QQuickWindow* window = this->window();
    2. if(window)
    3. {
    4. QOpenGLFramebufferObject* FBOobject = window->renderTarget();
    5. if(FBOobject)
    6. {
    7. //...
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

    But, renderTarget returned null value. I guess I should create FBO.

    Also, I tried this one, but it doesn't work:
    Qt Code:
    1. QOpenGLFramebufferObjectFormat format;
    2. format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
    3. QOpenGLFramebufferObject* FBOobject = new QOpenGLFramebufferObject(window->size(), format);
    4.  
    5. FBOobject->bind();
    6. glViewport(0, 0, window->size().width(), window->size().height());
    7.  
    8. glFlush();
    9.  
    10. FBOobject->bindDefault();
    11.  
    12. if(FBOobject)
    13. {
    14. QImage image = FBOobject->toImage();
    15. image.save(path)
    16. }
    17. delete FBOobject;
    To copy to clipboard, switch view to plain text mode 

    Could you please provide an example how to render the window to an FBO?

Similar Threads

  1. Replies: 4
    Last Post: 10th July 2014, 16:22
  2. Android ARM vs Android x86 in qmake .pro file
    By sedi in forum Qt Programming
    Replies: 1
    Last Post: 12th May 2014, 09:48
  3. How do you make android applications display correctly on android phone?
    By Cyrebo in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 17th August 2013, 08:31
  4. How to take ScreenShot Qt/QML
    By stereoMatching in forum Qt Quick
    Replies: 1
    Last Post: 15th June 2013, 11:47
  5. Screenshot
    By graciano in forum Qt Programming
    Replies: 3
    Last Post: 19th April 2009, 17:32

Tags for this Thread

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.