简体   繁体   English

CImg库未加载图像

[英]CImg library not loading image

I have followed the CImg tutorial and I it works perfectly. 我已经遵循了CImg 教程 ,并且效果很好。 However, if I try to load a different image (other than lena.jpg), I get a stack overflow error. 但是,如果尝试加载其他图像(lena.jpg除外),则会出现堆栈溢出错误。

For example, this works: 例如,这有效:

CImg<float> image;
string filePath = "C:/Users/zzz/Documents/lena.jpg";
image.load(filePath.c_str());

But this gives an error: 但这给出了一个错误:

CImg<float> image;
string filePath = "C:/Users/zzz/Documents/anotherimage.jpg";
image.load(filePath.c_str());

The error is: Unhandled exception at 0x77bb15de in LoadImageTest.exe: 0xC00000FD: Stack overflow. 错误是:LoadImageTest.exe中0x77bb15de的未处理异常:0xC00000FD:堆栈溢出。

I thought the stack overflow was due to "anotherimage.jpg" being too large, so I also tried a really small image (16x16 pixels). 我以为堆栈溢出是由于“ anotherimage.jpg”太大,所以我还尝试了一个非常小的图像(16x16像素)。 This resulted in the same error. 这导致了同样的错误。

Does anyone have any suggestions as to why this is happening? 有人对为什么会这样有什么建议吗?

Full code: 完整代码:

#include "stdafx.h"
#include <iostream>

#include "CImg.h"

using namespace cimg_library;
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    CImg<float> image;

    // This works...
    string filePath = "C:/Users/zzz/Pictures/lena.jpg";

    // This doesn't work...
    // string filePath = "C:/Users/zzz/Pictures/small.jpg";

    image.load(filePath.c_str());

    CImgDisplay main_disp(image, "The image");

    while (!main_disp.is_closed())
    {
        main_disp.wait();
    }

    return 0;
}

Looks weird. 看起来很奇怪。 Are you sure this is indeed a file in JPG format ? 您确定这确实是JPG格式的文件吗? Does it use some special JPEG formats (B&W, 12 bits ?, ...). 它是否使用某些特殊的JPEG格式(黑白,12位?,...)。

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

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