How to get a screenshot in Android?
-
wrote on 31 Jul 2019, 16:24 last edited by
I get error:use of undeclared identifier 'fullScreen'
-
wrote on 31 Jul 2019, 16:26 last edited by KroMignonThis post is deleted!
-
wrote on 31 Jul 2019, 16:34 last edited by
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();
-
wrote on 31 Jul 2019, 16:36 last edited by
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; -
wrote on 31 Jul 2019, 16:38 last edited by
Maybe you can use it?
foreach(QObject* obj, engine.rootObjects()) {
QQuickWindow* window = qobject_cast<QQuickWindow*>(obj);
if (window) {
QImage image = window->grabWindow();
qDebug() << image;
}
} -
is the image valid then ?
like
qDebug() << image.isNull();
says false ? -
wrote on 31 Jul 2019, 17:01 last edited by Mikeeeeee
qDebug()<<"screenShot:"<<image;
return:
"screenShot: "data:image/png;base64,"" -
wrote on 31 Jul 2019, 17:04 last edited by
@mrjj said in How to get a screenshot in Android?:
qDebug() << image.isNull();
qDebug() <<"image.isNull() :" << image.isNull();
return:
image.isNull() : false -
@mrjj said in How to get a screenshot in Android?:
qDebug() << image.isNull();
qDebug() <<"image.isNull() :" << image.isNull();
return:
image.isNull() : false@mikeeeeee
Ok, that means its does grab something :) -
wrote on 31 Jul 2019, 17:07 last edited by
But how to get a picture out of it?
-
@mikeeeeee
Cant you just save it ?
https://doc.qt.io/qt-5/qimage.html#save -
wrote on 31 Jul 2019, 17:26 last edited by
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.
-
wrote on 31 Jul 2019, 17:29 last edited by
qDebug() <<"image.isNull() :" << image.isNull()<<"screen->size() :"<<screen->size();
return
image.isNull() : false screen->size() : QSize(360, 640) -
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.
@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/38501975What Qt version are you using?
-
wrote on 31 Jul 2019, 17:30 last edited by
Could the screen be incorrectly processed?
-
wrote on 31 Jul 2019, 17:31 last edited by
I use Qt 5.13
-
wrote on 31 Jul 2019, 17:32 last edited by
my initial code worked in Windows, but it doesn't work in Android.
-
@mikeeeeee
Hi
Not all android devices can take shot of QML. Need support in openGL driver.Hmm. your Qt version seems new enough.
if you google "qt qml grabwindow bug" you can see there been quite some issues but
it should work with new Qt versions.How type of android device are you using ? I mena is it old or kinda new ?
-
wrote on 31 Jul 2019, 17:36 last edited by
I use Android 5,6,9
-
@mikeeeeee
Well if possible you can try on another android device to see if same happens.
15/29