Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to get a screenshot in Android?

How to get a screenshot in Android?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
29 Posts 3 Posters 3.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mikeeeeee
    wrote on 31 Jul 2019, 14:36 last edited by
    #1

    Hi!
    How to get a screenshot in Android?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 31 Jul 2019, 14:42 last edited by
      #2

      Hi
      of your own app ?
      or of whole "Desktop" / other app.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mikeeeeee
        wrote on 31 Jul 2019, 15:44 last edited by
        #3

        I will be satisfied with any screenshot, application or desktop. My application on QML.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Mikeeeeee
          wrote on 31 Jul 2019, 15:58 last edited by
          #4

          I use QQmlApplicationEngine

          K 1 Reply Last reply 31 Jul 2019, 16:08
          0
          • M Mikeeeeee
            31 Jul 2019, 15:58

            I use QQmlApplicationEngine

            K Offline
            K Offline
            KroMignon
            wrote on 31 Jul 2019, 16:08 last edited by
            #5

            @mikeeeeee I would to it like this:

            QQuickWindow* currentWindow = qobject_cast<QQuickWindow*>(QGuiApplication::focusWindow());
            if(!currentWindow)
                return;
            QScreen* screen = currentWindow->screen();
            if(!screen)
                return;
            QRect screenGeometry = fullScreen ? screen->geometry() : currentWindow->geometry();
            auto pm = screen->grabWindow(0, screenGeometry.x(), screenGeometry.y(), screenGeometry.width(), screenGeometry.height());
            
            QByteArray bArray;
            QBuffer buffer(&bArray);
            buffer.open(QIODevice::WriteOnly);
            pm.save(&buffer, "PNG");
            
            
            1 Reply Last reply
            1
            • M Offline
              M Offline
              Mikeeeeee
              wrote on 31 Jul 2019, 16:24 last edited by
              #6

              I get error:use of undeclared identifier 'fullScreen'

              K 1 Reply Last reply 31 Jul 2019, 16:26
              0
              • M Mikeeeeee
                31 Jul 2019, 16:24

                I get error:use of undeclared identifier 'fullScreen'

                K Offline
                K Offline
                KroMignon
                wrote on 31 Jul 2019, 16:26 last edited by KroMignon
                #7
                This post is deleted!
                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  Mikeeeeee
                  wrote on 31 Jul 2019, 16:34 last edited by
                  #8

                  This piece of code doesn't work either. I put in my code that converts QScreen to QByteArray. QByteArray is empty.

                  QQuickWindow* currentWindow = qobject_cast<QQuickWindow*>(QGuiApplication::focusWindow());
                  //    if(!currentWindow)
                  //        return;
                       QScreen* screen = currentWindow->screen();
                  
                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    Mikeeeeee
                    wrote on 31 Jul 2019, 16:36 last edited by
                    #9

                    This all code

                    QQuickWindow* currentWindow = qobject_cast<QQuickWindow*>(QGuiApplication::focusWindow());
                    

                    // if(!currentWindow)
                    // return;
                    QScreen* screen = currentWindow->screen();
                    // if(!screen)
                    // return;
                    //QRect screenGeometry = fullScreen ? screen->geometry() : currentWindow->geometry();
                    /* QRect screenGeometry = fullScreen ? screen->geometry() : currentWindow->geometry();
                    auto pm = screen->grabWindow(0, screenGeometry.x(), screenGeometry.y(), screenGeometry.width(), screenGeometry.height());

                    QByteArray bArray;
                    QBuffer buffer(&bArray);
                    buffer.open(QIODevice::WriteOnly);
                    pm.save(&buffer, "PNG");*/
                    
                    
                    
                    QImage myScreen;
                    //QPixmap pic = QPixmap::grabWindow(QWidget::winId(),0,0,50,50);
                    //qDebug()<<QWidget::winId();
                    

                    // QScreen *screen = QGuiApplication::primaryScreen();
                    QPixmap pixamp;
                    pixamp = screen->grabWindow(0);
                    myScreen = pixamp.toImage();
                    //myScreen = QPixmap::grabWindow();
                    //myScreen = quickView->grabWindow();
                    //myScreen.save("C:\Users\New Owner\Downloads\i.png");
                    QByteArray bArray;
                    QBuffer buffer(&bArray);
                    buffer.open(QIODevice::WriteOnly);
                    //myScreen.save(&buffer, "JPEG");
                    //QString image("data:image/jpg;base64,");
                    myScreen.save(&buffer, "PNG");
                    QString image("data:image/png;base64,");
                    image.append(QString::fromLatin1(bArray.toBase64().data()));
                    qDebug()<<"screenShot:"<<image;
                    return image;

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      Mikeeeeee
                      wrote on 31 Jul 2019, 16:38 last edited by
                      #10

                      Maybe you can use it?

                      foreach(QObject* obj, engine.rootObjects()) {
                      QQuickWindow* window = qobject_cast<QQuickWindow*>(obj);
                      if (window) {
                      QImage image = window->grabWindow();
                      qDebug() << image;
                      }
                      }

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on 31 Jul 2019, 16:39 last edited by
                        #11

                        is the image valid then ?
                        like
                        qDebug() << image.isNull();
                        says false ?

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          Mikeeeeee
                          wrote on 31 Jul 2019, 17:01 last edited by Mikeeeeee
                          #12

                          qDebug()<<"screenShot:"<<image;
                          return:
                          "screenShot: "data:image/png;base64,""

                          1 Reply Last reply
                          0
                          • M Offline
                            M Offline
                            Mikeeeeee
                            wrote on 31 Jul 2019, 17:04 last edited by
                            #13

                            @mrjj said in How to get a screenshot in Android?:

                            qDebug() << image.isNull();

                            qDebug() <<"image.isNull() :" << image.isNull();
                            return:
                            image.isNull() : false

                            M 1 Reply Last reply 31 Jul 2019, 17:06
                            0
                            • M Mikeeeeee
                              31 Jul 2019, 17:04

                              @mrjj said in How to get a screenshot in Android?:

                              qDebug() << image.isNull();

                              qDebug() <<"image.isNull() :" << image.isNull();
                              return:
                              image.isNull() : false

                              M Offline
                              M Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on 31 Jul 2019, 17:06 last edited by
                              #14

                              @mikeeeeee
                              Ok, that means its does grab something :)

                              1 Reply Last reply
                              0
                              • M Offline
                                M Offline
                                Mikeeeeee
                                wrote on 31 Jul 2019, 17:07 last edited by
                                #15

                                But how to get a picture out of it?

                                M 1 Reply Last reply 31 Jul 2019, 17:18
                                0
                                • M Mikeeeeee
                                  31 Jul 2019, 17:07

                                  But how to get a picture out of it?

                                  M Offline
                                  M Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on 31 Jul 2019, 17:18 last edited by
                                  #16

                                  @mikeeeeee
                                  Cant you just save it ?
                                  https://doc.qt.io/qt-5/qimage.html#save

                                  1 Reply Last reply
                                  0
                                  • M Offline
                                    M Offline
                                    Mikeeeeee
                                    wrote on 31 Jul 2019, 17:26 last edited by
                                    #17

                                    We've made a mistake. I immediately ask the text QString image("data:image/png;base64,"); And so, pictures of the there is no. Need another code.

                                    M 1 Reply Last reply 31 Jul 2019, 17:30
                                    0
                                    • M Offline
                                      M Offline
                                      Mikeeeeee
                                      wrote on 31 Jul 2019, 17:29 last edited by
                                      #18

                                      qDebug() <<"image.isNull() :" << image.isNull()<<"screen->size() :"<<screen->size();
                                      return
                                      image.isNull() : false screen->size() : QSize(360, 640)

                                      1 Reply Last reply
                                      0
                                      • M Mikeeeeee
                                        31 Jul 2019, 17:26

                                        We've made a mistake. I immediately ask the text QString image("data:image/png;base64,"); And so, pictures of the there is no. Need another code.

                                        M Offline
                                        M Offline
                                        mrjj
                                        Lifetime Qt Champion
                                        wrote on 31 Jul 2019, 17:30 last edited by
                                        #19

                                        @mikeeeeee
                                        Im really not sure what you are saying. :)
                                        That code work for others it seemed
                                        https://stackoverflow.com/questions/21697185/how-to-take-screenshot-of-qml-application-without-qquickview/38501975

                                        What Qt version are you using?

                                        1 Reply Last reply
                                        0
                                        • M Offline
                                          M Offline
                                          Mikeeeeee
                                          wrote on 31 Jul 2019, 17:30 last edited by
                                          #20

                                          Could the screen be incorrectly processed?

                                          1 Reply Last reply
                                          0

                                          4/29

                                          31 Jul 2019, 15:58

                                          topic:navigator.unread, 25
                                          • Login

                                          • Login or register to search.
                                          4 out of 29
                                          • First post
                                            4/29
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved