向量中的向量 - 传递给函数

问题描述 投票:0回答:0

我有一个写入 .png 图像的函数。它对于一张图像效果很好,但我试图在运行时创建向量。下面的代码不起作用。

这一行给了我一个错误。 "encodeOneStep(combined_file_path.c_str(), vect[0], width, height); // 写入 .png "

const size_t width = 256, height = 256;
    const size_t no_elems = width * height * 4;

    using Image = std::vector<char>;
    std::vector<Image> vect(3, Image(no_elems));

    CString File_Path;
    char sztmp[1024];
    const char* filepath = " ";

    string combined_file_path(string(filepath) + to_string(X) + ".png");
    encodeOneStep(combined_file_path.c_str(), vect[0], width, height);  // Write the .png image file.

这是我需要向其传递向量的函数。

//Encode from raw pixels to disk with a single function call
//The image argument has width * height RGBA pixels or width * height * 4 bytes
void encodeOneStep(const char* filename, std::vector<unsigned char>& image, unsigned width, unsigned height) {
    //Encode the image
    unsigned error = lodepng::encode(filename, image, width, height);

    //if there's an error, display it
    if (error) std::cout << "encoder error " << error << ": " << lodepng_error_text(error) << std::endl;
}

这适用于一个图像矢量...

const unsigned width = 256, height = 256, no_elems = 262144; // no_elems is the size of the png image array.
    std::vector<unsigned char> image(no_elems);

encodeOneStep(combined_file_path.c_str(), image, width, height);  // Write the .png image file.
c++ function vector png
© www.soinside.com 2019 - 2024. All rights reserved.