功能一
- 保存图像数据到本地为JPG/PNG格式;
- 并且文件名为当前系统的日期时间。
函数实现
| bool save_image(QImage imageData,QString curTime,QString savePath) |
| { |
| |
| if(imageData.save(QString("%1/%2.png").arg(savePath,curTime),"PNG",100)) |
| return true; |
| else |
| return false; |
| } |
参数说明
-
QImage imageData:图像数据
-
QString curTime :为系统时间
| |
| QDateTime curDateTime = QDateTime::currentDateTime(); |
| QString curTime = curDateTime.toString("yyyy-MM-dd hh:mm:ss:zzz"); |
扩展:
| |
| QDateTime curDateTime(QDateTime::fromString(curTime,"yyyy-MM-dd hh:mm:ss:zzz")); |
- QString savePath:保存文件路径
功能二
- 创建文件夹,并且保存字符为json/txt 等格式文件。
函数实现
| #define DIRNAME "./DataDoc" |
| |
| |
| void SaveToJsonFile(Json::Value JsonMessage) |
| { |
| |
| QDir dir(QDir::currentPath()); |
| if(!dir.exists(DIRNAME)) |
| dir.mkdir(DIRNAME); |
| dir.cd(DIRNAME); |
| |
| |
| QFile newFile(QString("%1/%2.json").arg(DIRNAME,curTime)); |
| if(!newFile.open(QIODevice::WriteOnly | QIODevice::Text)) |
| std::cout<<"Open NewFile failed!"<<std::endl; |
| |
| |
| newFile.write(JsonMessage.toStyledString().c_str()); |
| |
| newFile.close(); |
| } |
参数说明
- Json::Value JsonMessage :为Json数据,格式如下
| { |
| "messageBody" : { |
| "background_color" : "#DD22DD", |
| "limit_style" : "timer", |
| "limit_time" : "2023-01-12 15:00:03,2023-01-17 12:31:00", |
| "text" : "这是一个提示文本测试", |
| "text_color" : "#1A94E6", |
| "text_direction" : "to_left", |
| "text_fontSize" : "50", |
| "text_id" : "111111", |
| "text_scrollInterval" : "5" |
| }, |
| "messageCommand" : "PLAY_PROMPT_TEXT", |
| "messageState" : "wait" |
| } |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性