简体   繁体   English

CImg读取图像异常

[英]CImg reading image exception

I am using CImg to read a .png file, like following: 我正在使用CImg读取.png文件,如下所示:

// DGT.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include "..\CImg\CImg.h"

using namespace std;
using namespace cimg_library;

long ReadImage(char *fileName)
{
    CImg<unsigned char> image(fileName); // stackover flow exceptions thrown here.

    return 0;
}

int _tmain(int argc, _TCHAR* argv[])
{
    ReadImage("D:\\Projects\\DGT\\DGT\\shepplogan256.png");
    return 0;
}

However, the stack overflown exceptions is thrown at CImg<unsigned char> image(fileName); 但是,堆栈溢出异常将在CImg<unsigned char> image(fileName);处抛出CImg<unsigned char> image(fileName); when trying to load the image. 尝试加载图像时。 The image is there, so I am wondering where I messed up and how to read the image? 图像在那里,所以我想知道我在哪里弄乱了,以及如何阅读图像?

您需要libpngimagemagick才能使用CImg加载PNG文件。

To read .jpeg or .png files natively, CImg needs you to link your code with either libpng or libjpeg, and that you define macros cimg_use_png or cimg_use_jpeg . 要本地读取.jpeg或.png文件,CImg需要您将代码与libpng或libjpeg链接,并定义宏cimg_use_pngcimg_use_jpeg By doing so, ImageMagick is not required at all. 这样,根本不需要ImageMagick。 I prefer this solution as it does not require installing a new (external) software to read image files, and eases the distribution of the binaries as well. 我更喜欢这种解决方案,因为它不需要安装新的(外部)软件来读取图像文件,并且还简化了二进制文件的分发。

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

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