我正在使用 Cimg 图形库编写小型 C 程序,需要测试文件是否为图像。
我试图加载文件/图像
CImg<unsigned char> srcimg(filename)
并获得豁免,但 cimg 断然退出:
convert.im6: improper image header `pok.txt' @ error/bmp.c/ReadBMPImage/603.
convert.im6: no images defined `pnm:-' @ error/convert.c/ConvertImageCommand/3044.
sh: 1: gm: not found
terminate called after throwing an instance of 'cimg_library::CImgIOException'
what(): [instance(0,0,0,0,(nil),non-shared)] CImg<unsigned char>::load() : Failed to recognize format of file 'pok.txt'.
Aborted
当然,文件是txt,但是忽略后缀,有没有正确的方法来测试呢?不涉及其他依赖项/库。
谢谢