如何在C ++中将字节数组转换回jpeg

因此,在下面的代码中,我使用fstream读取文件并将其转换为字节向量,我想知道是否存在一种无需下载外部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];
    }



}

wsf945162 回答:如何在C ++中将字节数组转换回jpeg

您已经知道了。

您读取了构成JPEG文件的所有字节。

你仍然有他们。

您可以立即将它们写回到磁盘,或执行其他任何操作。

本文链接:https://www.f2er.com/3136274.html

大家都在问