麒麟截图里的用grabWindow的代码,抓取部分看起来相似
for (QScreen * const screen : QGuiApplication::screens()) {
geometry = geometry.united(screen->geometry());
rects.append(screen->geometry());
}
QPixmap p1(QApplication::primaryScreen()->grabWindow(
QApplication::desktop()->winId(),
geometry.x(),
geometry.y(),
geometry.width(),
geometry.height())
);
QPixmap p(p1.width(), p1.height());
p.fill(QColor(Qt::black));
QPainter painter(&p);
auto screenNumber = QApplication::desktop()->screenNumber();
QScreen *screen = QApplication::screens()[screenNumber];
for (QRect const &rect : rects) {
QPixmap p2 = p1.copy(
QRect(rect.x() * screen->devicePixelRatio(),
rect.y() * screen->devicePixelRatio(),
rect.width() * screen->devicePixelRatio(),
rect.height() * screen->devicePixelRatio())
);
painter.drawPixmap(
QRect(rect.x() * screen->devicePixelRatio(),
rect.y() * screen->devicePixelRatio(),
rect.width() * screen->devicePixelRatio(),
rect.height() * screen->devicePixelRatio()),
p2);
}
p.setDevicePixelRatio(screen->devicePixelRatio());
return p;
|