zoukankan      html  css  js  c++  java
  • 截取屏幕

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    
    #include <QMainWindow>
    
    
    #include <QTimer>  //定时期
    #include <QPixmap>  //图像类
    #include <QDesktopWidget>  //desktopwidget类提供对多头系统上屏幕信息的访问。
    #include <QMessageBox>
    
    
    namespace Ui {
    class MainWindow;
    }
    
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    
    public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();
    
    
    private slots:
        void on_newSreenShotbutton_clicked();
        void shotScreenSlot();
    
    
        void on_savePicturebutton_clicked();
    
    
    private:
        Ui::MainWindow *ui;
        QTimer *timer;
        QPixmap pixmap;
    };
    
    
    #endif // MAINWINDOW_H

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QScreen>  //The QScreen class is used to query screen properties qscreen类用于查询屏幕属性
    #include <QFileDialog>  //获取文件路径
    #include <QDesktopServices>  //桌面服务
    #include <QClipboard>   //剪切版
    #include <QDebug>
    //storagelocation
    
    
    //把内容放到剪切版剪切版   进程通信
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    }
    
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    
    void MainWindow::on_newSreenShotbutton_clicked()
    {
       if(ui->checkBox->isChecked())  //  单选框
            {
            this->hide();
            this->timer = new QTimer;
    //连接 定时期信号 和截屏槽函数
            QObject::connect(timer,SIGNAL(timeout()),this,SLOT(shotScreenSlot()));
            //启动定时器
            this->timer->start(ui->spinBox->value()*1000);
        }
        else
            {
            qApp->beep();
        }
        /*
        QClipboard *clipboard = QGuiApplication::clipboard();
         QString originalText = clipboard->text();
         ...
         clipboard->setText(newText);
        */
    }
    
    
    void MainWindow::shotScreenSlot()
    {
        //pixmap  当前应用程序所在屏幕 抓取
       // QScreen::grabWindow();
       // QScreen screen(this);
        this->pixmap = QPixmap::grabWindow(QApplication::desktop()->winId());
    // 图片的大小     为label_3 的大小
        ui->label_3->setPixmap(this->pixmap.scaled(ui->label_3->size()));
        //打开系统剪切版
        QClipboard *clipboard = QGuiApplication::clipboard();
         //QString originalText = clipboard->text();  //获得剪切版内的文本
        // ...  把图片放到剪切版
         clipboard->setPixmap(this->pixmap);
       qDebug()<<clipboard->pixmap().size();
        this->show();
        this->timer->stop();
    }
    
    
    void MainWindow::on_savePicturebutton_clicked()
    {//QDesktopServices::storageLocation(QDesktopServices::DataLocation)
     // QString filename=QFileDialog::getSaveFileName(this,"savefile",QDesktopServices::storageLocation(QDesktopServices::PicturesLocation);/home/centos/grapSreen/mainwindow.cpp:63: error: ‘storageLocation’ is not a member of ‘QDesktopServices’
              QString filename=QFileDialog::getSaveFileName(this,"savefile","/home/centos/图片");
      //pixmax 提供了保存接口
      this->pixmap.save(filename);
    }
    
    
    
    


  • 相关阅读:
    序列号Pickle模块
    随机数Random模块
    selenium保存cookies 实例02
    selenium读取浏览器已有Cookies 实例01
    selenium的简单演示程序
    java连接sftp服务器读取压缩包的文件(例:读取zip中的csv文件返回数组)
    java实现连接sftp服务器并下载文件到本地
    在idea中实现热部署
    java使用IText将数据导出为pdf文件(数据为excel表格样式)
    使用poi解析Excel文件转化数组形式的集合(List<String[] list)
  • 原文地址:https://www.cnblogs.com/countryboy666/p/11067861.html
Copyright © 2011-2022 走看看