CImg 错误:"gm.exe"未被识别为内部或外部命令,

CImg Error : 'gm.exe' is not recognized as an internal or external command,

本文关键字:内部 外部 命令 识别 错误 gm exe CImg      更新时间:2023-10-16

我是c++编程的新手,今天我试图使用CImg保存图像。CImg是C++模板图像处理库。

写的基本代码是(请原谅任何语法错误,作为我代码的一部分复制):

#include "CImg.h"// Include CImg library header.
#include <iostream>
using namespace cimg_library;
using namespace std;
const int screen_size = 800;
//-------------------------------------------------------------------------------
//  Main procedure
//-------------------------------------------------------------------------------
int main()
{
CImg<unsigned char> img(screen_size,screen_size,1,3,20);
CImgDisplay disp(img, "CImg Tutorial");   
//Some drawing using img.draw_circle( 10, 10, 60, RED);
img.save("result.jpg"); // save the image    
return 0;   
}

但是我不能按照它说的那样运行我的程序:

Invalid Parameter - 100%
'gm.exe' is not recognized as an internal or external command,
operable program or batch file.
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
[CImg] *** CImgIOException *** [instance(800,800,1,3,02150020,non-shared)] CImg<unsigned char>::save_other() : Failed to save file 'result.jpg'. Format is not natively supported, and no external commands succeeded.
terminate called after throwing an instance of 'cimg_library::CImgIOException'
  what():  [instance(800,800,1,3,02150020,non-shared)] CImg<unsigned char>::save_other() : Failed to save file 'result.jpg'. Format is not natively supported, and no external commands succeeded.

虽然我可以看到图像,但我无法保存它。谷歌搜索了一下后,我发现有人说要安装ImageMagick,我已经安装了它,但没有帮助。一些论坛说要针对libjpeg,libpng,libmagick++进行编译。但是我不知道如何针对这些库进行编译。我正在使用Eclipse CDT插件来编写C++项目。请帮助我.

我遇到了同样的错误,安装GraphicsMagick(不是ImageMagick)对我有帮助。

我已经从 ftp://ftp.graphicsmagick.org/pub/GraphicsMagick/windows/下载并安装了GraphicsMagick-1.3.26-Q8-win64-dll.exe。如果需要,您可以选择另一个:

请注意,QuantumDepth=8版本(Q8)提供了工业 标准 24/32 位像素消耗一半的内存,减少约 30% CPU 比提供 48/64 位的 QuantumDepth=16 版本 (Q16) 高 像素用于高分辨率颜色。Q8 版本适合处理 用于在计算机屏幕上查看的典型照片。如果你是 处理胶片、科学或医学图像,使用 ICC 颜色 配置文件,或处理对比度有限的图像,然后Q16 建议使用版本。

重要提示:在安装过程中,请勿删除"更新可执行搜索路径"复选框,该复选框会更新环境变量 %PATH%,使gm.exe可从任何地方使用。

就我而言,还需要安装Ghostscript - 强烈建议GraphicsMagick安装。有一个指向x64 Ghostscript的链接:https://sourceforge.net/projects/ghostscript/files/GPL%20Ghostscript/9.09/gs909w64.exe/download(我把它放在这里,因为来自GraphicMagick网站的链接只会引导你进入32位)。

在那之后,它对我来说效果很好。

对于某些图像格式(如.jpg.png.tif以及基本上所有需要数据压缩的格式),CImg 将尝试使用外部工具来保存它们(例如来自 ImageMagick 的convert或来自 GraphicsMagick 的gm)。如果您没有安装任何文件,那么如果不将代码与 libjpeg 库链接,您将无法保存.jpg文件,以获得对 JPEG 读/写的本机支持(然后,您需要在#include "CImg.h"之前#define cimg_use_jpeg,告诉库您想使用 libjpeg 功能)。

如果你想让事情变得更简单,我建议使用另一种(非压缩的)图像格式保存你的图像,如.bmp.ppm。这些格式由 CImg 本机处理,不需要与外部库链接。

我知道这个问题很老,但我在一个项目上一直遇到同样的错误,而不是在另一个项目上,这是谷歌上唯一的事情。

要摆脱它,您必须做两件事:

  1. 为适当的操作系统和架构安装动态 ImageMagick 库(32/64)。链接

  2. 我使用的是VisualStudio,字符集必须设置为"Unicode"。当我恢复为多字节字符集时,错误会再次出现。我想这与 CImg 处理字符串并错误比较它们的方式有关。