所以在下面的代码中,我使用 fstream 读取文件并将其转换为字节 vector ,我想知道是否有一种方法可以在不下载外部 C++ 库的情况下将其转换回 jpeg 图像。我觉得应该有一种方法可以获取字节数组并以某种方式返回图像。
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 文件的所有字节。
你还有它们。
你现在可以将它们写回磁盘,或者做任何你想做的事。
关于c++ - 你如何在 C++ 中将字节数组转换回 jpeg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58770857/