简体   繁体   English

在Android上使用Qt C ++截图

[英]Taking Screenshots Using Qt C++ on Android

thanks for checking my question out! 谢谢你检查我的问题!

I'm currently working on a project using Qt C++, which is designed to be multi-platform. 我目前正在使用Qt C ++开发一个项目,该项目旨在实现多平台。 I'm a bit of a newcoming to it, so I've been asked to set up the ability to take screenshots from within the menu structure, and I'm having issues with the Android version of the companion app. 我对它有点新意,所以我被要求设置从菜单结构中截取屏幕截图的能力,而且我对配套应用程序的Android版本存在问题。

As a quick overview, it's a bit of software that send the content of a host PC's screen to our app, and I've been able to take screenshots on the Windows version just fine, using QScreen and QPixmap, like so: 作为一个快速概述,它是一些软件将主机PC屏幕的内容发送到我们的应用程序,我已经能够使用QScreen和QPixmap在Windows版本上截取屏幕截图,如下所示:

overlaywindow.cpp overlaywindow.cpp

{
    QPixmap screenSnapData = screenGrab->currentBackground();
}

screenGrabber.cpp screenGrabber.cpp

{
    QScreen *screen = QGuiApplication::primaryScreen();
    return screen->grabWindow( QApplication::desktop()->winId() );
}

Unfortunately, Android seems to reject QScreen, and with most suggestions from past Google searches suggesting the now-deprecated QPixmap::grab(), I've gotten a little stuck. 不幸的是,Android似乎拒绝了QScreen,而且过去谷歌搜索中的大多数建议都暗示了现在已经弃用的QPixmap :: grab(),我有点陷入困境。

What luck I have had is within the code for the menu itself, and QWidget, but that isn't without issue, of course! 什么运气在菜单本身的代码和QWidget中,但当然不是没有问题!

QFile doubleCheckFile("/storage/emulated/0/Pictures/Testing/checking.png");
doubleCheckFile.open(QIODevice::ReadWrite);
QPixmap checkingPixmap = QWidget::grab();
checkingPixmap.save(&doubleCheckFile);
doubleCheckFile.close();

This code does take a screenshot, but only of the button strip currently implemented, and not for the whole screen. 此代码确实采用屏幕截图,但仅限于当前实现的按钮条,而不是整个屏幕。 I've also taken a 'screenshot' of just a white box with the screen's dimensions by using: 我还使用以下方法拍摄了一个带有屏幕尺寸的白色框的“屏幕截图”:

QDesktopWidget dw;
QWidget *screen=dw.screen();         
QPixmap checkingPixmap = screen->grab();

Would anyone know of whether there was an alternative to using QScreen to take a screenshot in Android, or whether there's a specific way to get it working as compared to Windows? 是否有人知道是否有替代方法使用QScreen在Android中截取屏幕截图,或者是否有一种特定的方式让它与Windows相比有效? Or would QWidget be the right track? 或者QWidget会成为正确的轨道? Any help's greatly appreciated! 任何帮助都非常感谢!

as i can read in Qt doc : In your screenGrabber.cpp : 我可以在Qt doc中阅读:在你的screenGrabber.cpp中:

QScreen *screen = QGuiApplication::primaryScreen();
return screen->grabWindow( QApplication::desktop()->winId() );

replace with : 用。。。来代替 :

QScreen *screen = QGuiApplication::primaryScreen();
return screen->grabWindow( 0 ); // as 0 is the id of main screen

If you want to take a screenshot of your own widget, you can use the method QWidget::render ( Qt Doc ): 如果你想截取你自己的小部件的截图,你可以使用方法QWidget::renderQt Doc ):

QPixmap pixmap(widget->size());
widget->render(&pixmap);

If you want to take a screenshot of another app/widget than your app, you should use the Android API... 如果您想截取除您的应用之外的其他应用/小部件的屏幕截图,您应该使用Android API ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM