简体   繁体   English

尝试使用CImg保存图像时出错

[英]Error when attempting to save image with CImg

I am attempting to generate map tiles from a world generator that I have adapted using libnoise. 我试图从我使用libnoise改编的世界生成器中生成地图图块。 Using the libnoise saving methods work fine, but when attempting to scale and crop images using CImg, i get the following error: 使用libnoise保存方法可以正常工作,但是当尝试使用CImg缩放和裁剪图像时,出现以下错误:

[CImg] *** CImgIOException *** cimg::fopen(): Failed to open file '~/tiles/0/0/0.bmp' with mode 'wb'.

Relevant method: 相关方法:

void makeTile(CImg<unsigned char> image, int zoom, int x, int y, int depth, int argc, char* argv[]) {
    std::string directoryBase = "mkdir -p ~/tiles/" + boost::lexical_cast<std::string>(zoom);
    std::string directory = directoryBase + "/" + boost::lexical_cast<std::string>(x);
    std::string filename = "~/tiles/" + boost::lexical_cast<std::string>(zoom) + "/" + boost::lexical_cast<std::string>(x) + "/" + boost::lexical_cast<std::string>(y) + ".bmp";

    const char* file_o = cimg_option("-o", filename.c_str(), "Output file");
    system(directoryBase.c_str());
    system(directory.c_str());
    std::cout << "Made required dirs\n";
    CImg<unsigned char> imageClone = image.get_resize(256, 256, -100, -100, 1);

    std::cout << "scaled image\n";
    imageClone.save(file_o);

    if (depth > 0) {
        int smallX = x * 2;
        int smallY = y * 2;
        makeTile(image.get_crop(0, 0, image._width / 2, image._height / 2), zoom + 1, smallX, smallY, depth - 1, argc, argv);
        makeTile(image.get_crop(image._width / 2, 0, image._width, image._height / 2), zoom + 1, smallX + 1, smallY, depth - 1, argc, argv);
        makeTile(image.get_crop(0, image._height / 2, image._width / 2, image._height), zoom + 1, smallX, smallY + 1, depth - 1, argc, argv);
        makeTile(image.get_crop(image._width / 2, image._height / 2, image._width, image._height), zoom + 1, smallX + 1, smallY + 1, depth - 1, argc, argv);
    }
}

The image sent to this method on the first loop is the generated map from libnoise and loaded using CImg. 在第一个循环上发送到此方法的图像是从libnoise生成的映射,并使用CImg加载。

~/tiles/0/0/0.bmp is definitely not a valid filename. ~/tiles/0/0/0.bmp绝对不是有效的文件名。 I suspect you thought ~ would be replaced by the value of your $HOME , but this is not the case (this replacement is done only when writing a shell command, eg with bash ). 我怀疑您以为~将被$HOME的值替换,但事实并非如此(仅当编写shell命令(例如,使用bash )时才执行此替换)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM