QT截屏功能并保存:
void KScreenShot::FullScreenShot(const QString& filePath,int& width,int& height,const char* format)
{
// 抓取屏幕
QPixmap fullScreenShot = QPixmap::grabWindow(QApplication::desktop()->winId(),0,0,width,height);
// 判断文件目录是否存在,不存在则创建
QDir* fileDir = new QDir();
bool isFileExist = fileDir->exists(filePath);
if (!isFileExist)
{
fileDir->mkdir(filePath);
}
// 获取当前系统时间
QDateTime curTime = QDateTime::currentDateTime();
// 根据系统时间给截屏图像命名:ScreenShot-yyyyMMddhhmmss.jpg
QString fileName = filePath;
fileName.append("/ScreenShot-");
// 格式化时间
fileName.append(curTime.toString("yyyyMMddhhmmss"));
fileName.append(".");
fileName.append(format);
// 保存截屏图像
fullScreenShot.save(fileName,format);
// 发送消息更新剪贴板
KObject().SendMsg(K_OBJ_UPDATE_CLIP,K_MSG_UPDATE_CLIP, 0, (long)&fullScreenShot);
RELEASE_POINTER(fileDir);
}