c++ - 如何在 C++ 中将字节数组转换回 jpeg
问题描述
因此,在下面的代码中,我使用 fstream 读取文件并将其转换为字节向量,我想知道是否有办法将其转换回 jpeg 图像而无需下载外部 C++ 库。我觉得应该有一种方法可以获取字节数组并以某种方式返回图像。
std::vector<unsigned int> getByteArray(std::string filename){
// Define file stream object, and open the file
std::ifstream file (filename, std::ios::binary); //reads in the file
// Prepare iterator pairs to iterate the file content!
std::istream_iterator<unsigned char> begin(file), end; //creates an iterator of type unsigned char to read from begin of ile to end
std::vector<unsigned int> buffer(begin,end); //putting the values in a vector called buffer
//std::copy(buffer.begin(), buffer.end(), std::ostream_iterator<unsigned int>(std::cout <<","));
for(int i=0;i<buffer.size();i++){
std::cout<<buffer[i];
}
}
解决方案
你已经得到它了。
您读取了构成 JPEG 文件的所有字节。
你还有他们。
您现在可以将它们写回磁盘,或者做任何您想做的事情。
推荐阅读
- javascript - JavaScript 是否支持自动类型转换?
- javascript - 是否可以在滚动时为 flexbox 元素设置动画?
- java - 时间码没有返回正确的东西
- c# - 处理泄漏的 IAsyncDisposable 实例的推荐方法是什么?
- google-api - 故障排除:Google 日历插入 API 错误“权限不足:请求的身份验证范围不足”
- sql - 为什么“NOT NULL”不是约束?
- swift - 播放下载到缓存目录的歌曲
- python - 寻找一种聚类算法,该算法可以按质心周围的密度进行聚类,但具有固定的最大距离截止值
- java - Delta 时间在游戏引擎中无法正常工作 - LWJGL
- javascript - 如何在单击时修复此随机 URL 重定向