• 大小: 1.72MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-11-04
  • 语言: 其他
  • 标签: Qt  

资源简介

用Qt写的截图工具,实现了点击按钮背景色变暗,可用鼠标框选要截图的区域,并保存至本地文件。内含完整的工程文件。

资源截图

代码片段和文件信息

#include “capturescreen.h“

CaptureScreen::CaptureScreen(QWidget *parent Qt::WFlags flags)
: QMainWindow(parent flags)
{
ui.setupUi(this);

InitWindow();
}

CaptureScreen::~CaptureScreen()
{

}
void CaptureScreen::InitWindow()
{

Rubber = NULL;
ScreenHeight = 0;
ScreenWidth = 0;
info = new QImage(“infoa.png“);
GImage = QPixmap();
MouseStart = QPoint(00);
MouseEnd =QPoint(00);
//this->setMouseTracking(true);
//setWindowState(Qt::WindowActive | Qt::WindowFullScreen);

WholeWindow = QPixmap::grabWindow(QApplication::desktop()->winId());
WholeWindow.save(“tmp.png“);
bg = QImage(“tmp.png“);

QFile *tmp = new QFile(“tmp.png“);
tmp->remove();

ChangeLight(00bg.width() bg.height() 0.6);

//获取桌面尺寸
QDesktopWidget *desktop = QApplication::desktop();
QRect DesktopRect = desktop->screenGeometry();
ScreenWidth = DesktopRect.width();
ScreenHeight = DesktopRect.height();
this->resize(ScreenWidth ScreenHeight);
//按钮 点击之后就消失
BtnPress = new QPushButton(tr(“截图“) this);
BtnPress->setWindowFlags(Qt::framelessWindowHint | Qt::WindowStaysOnTopHint);
BtnPress->setGeometry(ScreenWidth/2 -100ScreenHeight/2 -2520050);
BtnPress->show();
connect(BtnPress SIGNAL(clicked()) BtnPress SLOT(close()));

Label = new QLabel(““this);
InfoLabel = new QLabel(““this);
Label->setWindowFlags(Qt::framelessWindowHint | Qt::WindowStaysOnTopHint);
this->setWindowFlags(Qt::framelessWindowHint);


}
void CaptureScreen::ChangeLight(int x int y int width int height double bright)
{
int redbluegreen;
for (int i=0; i {
for (int j=0; j {
red = qRed(bg.pixel(ij)) * bright;
green = qGreen(bg.pixel(ij)) * bright;
blue = qBlue(bg.pixel(ij)) * bright;
bg.setPixel(ijqRgb(red green blue));
}
}
}
void CaptureScreen::mousePressEvent(QMouseEvent *e)
{
if(e->button() == Qt::LeftButton)
{
InfoLabel->setPixmap(QPixmap::fromImage(*info));
InfoLabel->setWindowFlags(Qt::framelessWindowHint);
InfoLabel->move(QPoint(e->pos().x() + 30 e->pos().y()+30));
InfoLabel->show();

BtnPress->close();

//初始化框
if (!Rubber)
{
Rubber = new QRubberBand(QRubberBand::Line this);
}
Rubber->show();

//记录鼠标起始位置
MouseStart = e->pos();
//将框放置于起始位置
Rubber->setGeometry(MouseStart.x() MouseStart.y() 0 0);

//显示坐标
SetLabel();
}
else if (e->button() == Qt::RightButton)
{
BtnPress->close();
InfoLabel->close();
this->close();
}
}
void CaptureScreen::mouseDoubleClickEvent(QMouseEvent *e)
{
//截取全屏
if (e->button() == Qt::LeftButton)
{
BtnPress->close();
QString filename = QFileDialog::getSaveFileName(this tr(“save picture“) “.“ tr(“Image Files(*.png)“));

WholeWindow.save(filename);
InfoLabel->close();
this->close();
}
}
void CaptureScreen::mouseMoveEvent(QMouseEvent *e)
{
if (Rubber)
{
InfoLabel->move(QPoint(e->pos().x()+30 e->pos().y() +30));

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       5433  2018-11-22 09:41  CaptureScreen\CaptureScreen\capturescreen.cpp

     文件       1029  2018-11-22 09:41  CaptureScreen\CaptureScreen\capturescreen.h

     文件         73  2018-11-22 09:41  CaptureScreen\CaptureScreen\capturescreen.qrc

     文件        820  2018-11-22 09:41  CaptureScreen\CaptureScreen\capturescreen.ui

     文件      10209  2018-11-22 09:41  CaptureScreen\CaptureScreen\CaptureScreen.vcproj

     文件       2455  2018-11-22 09:41  CaptureScreen\CaptureScreen\GeneratedFiles\Debug\moc_capturescreen.cpp

     文件        739  2018-11-22 09:41  CaptureScreen\CaptureScreen\GeneratedFiles\qrc_capturescreen.cpp

     文件       2455  2018-11-22 09:41  CaptureScreen\CaptureScreen\GeneratedFiles\Release\moc_capturescreen.cpp

     文件       2416  2018-11-22 09:41  CaptureScreen\CaptureScreen\GeneratedFiles\ui_capturescreen.h

     文件        309  2018-11-22 09:41  CaptureScreen\CaptureScreen\main.cpp

     文件    9784320  2018-11-22 09:41  CaptureScreen\CaptureScreen.ncb

     文件        905  2018-11-22 09:41  CaptureScreen\CaptureScreen.sln

     文件      10240  2018-11-22 09:41  CaptureScreen\CaptureScreen.suo

     目录          0  2018-11-22 09:49  CaptureScreen\CaptureScreen\GeneratedFiles\Debug

     目录          0  2018-11-22 09:49  CaptureScreen\CaptureScreen\GeneratedFiles\Release

     目录          0  2018-11-22 09:49  CaptureScreen\CaptureScreen\GeneratedFiles

     目录          0  2018-11-22 09:41  CaptureScreen\CaptureScreen\Resources

     目录          0  2018-12-03 21:46  CaptureScreen\CaptureScreen

     目录          0  2018-12-03 21:45  CaptureScreen

----------- ---------  ---------- -----  ----

              9821403                    19


评论

共有 条评论