QT Capture Screen

Source: Internet
Author: User

Qpixmap Pixmap; The graphics class in the QT Library can handle all the graphics types supported by QT, such as jpg,bmp qpixmap pix; PIX = Pixmap.grabwindow (This->winid (), 0,0,-1,-1); This->winid () for obtaining the current window id//pix = pixmap.grabwidget (this,0,0,-1,-1); Can also use this method, they two difference is only the first parameter is not just the IF (Pix.isnull ()) {qmessagebox::information (this, "error", "Grab-screen failed", Qmessagebox::ok); } else {if (Pix.save ("grab.jpg") ==false) {qmessagebox::information (this, "right", "Save Error", Qmessagebox::ok);} else Qmessagebox::information (This, "Grab", "Bitmap saved as Grab.bmp", Qmessagebox::ok); }

The main methods of implementation are:

① use Qpixmap's Grabwindow to pick the window to grab the picture;

② then uses the bool Qpixmap::save (const QString & fileName, const char * format = 0, int quality =-1) const, named to save the crawled picture.

Note the point:

①:grabwidget represents the canvas portion of the captured window, and Grabwindow grabs the part with the caption box.

②grabwindow If the first parameter is 0, then the entire desktop is crawled.

★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★

※QT5 is used in the QScreen class, and then uses its Qpixmap qscreen::grabwindow (WId window, int x = 0, int y = 0, Intwidth =-1, int height =-1) method.

QScreen *screen = qguiapplication::p rimaryscreen (); Screen->grabwindow (This->winid (), 0,0,-1,-1). Save ("captureimg.jpg", "jpg");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.