stringstream到base64进行编码并将其发送到服务器ios

stringstream to base64 encode and send it to the server ios

本文关键字:服务器 ios base64 编码 stringstream      更新时间:2023-10-16

使用打开的cv,我得到cv::Mat格式的描述符。转换cv::Matstringstream是用这种方法发生的:

/// Serialize a cv::Mat to a stringstream
stringstream serialize(Mat input)
{
    // We will need to also serialize the width, height, type and size of the matrix
    int width = input.cols;
    int height = input.rows;
    int type = input.type();
    size_t size = input.total() * input.elemSize();
    // Initialize a stringstream and write the data
    stringstream ss;
    ss.write((char*)(&width), sizeof(int));
    ss.write((char*)(&height), sizeof(int));
    ss.write((char*)(&type), sizeof(int));
    ss.write((char*)(&size), sizeof(size_t));
    // Write the whole image data
    ss.write((char*)input.data, size);
    return ss;
}

现在我想把这个stringstream转换成base64编码的。如何使之成为可能的直接方法。

您可以对stringstream获得的string进行编码,如:

Mat m;
...
std::string s = serialize(m).str();
std::string encoded = base64_encode(s.c_str());
// send "encoded" to server

例如,可以在此处找到base64_encode的代码。