|
发表于 2023-10-17 23:16:32
|
显示全部楼层
山西省阳泉市
#include <stdio.h>
#include <opencv2/opencv.hpp>
int main() {
// 读取快照文件
cv::Mat snapshot = cv::imread("snapshot.bmp", cv::IMREAD_UNCHANGED);
if (snapshot.empty()) {
printf("无法读取快照文件!\n");
return -1;
}
// 将快照转换为JPG格式
std::vector<int> compression_params;
compression_params.push_back(cv::IMWRITE_JPEG_QUALITY);
compression_params.push_back(90); // 设置JPG质量,范围为0-100
std::string outputFilename = "output.jpg";
bool result = cv::imwrite(outputFilename, snapshot, compression_params);
if (result) {
printf("转换成功,已保存为%s\n", outputFilename.c_str());
} else {
printf("转换失败!\n");
return -1;
}
return 0;
} |
|