CImg 错误:"gm.exe"未被识别为内部或外部命令,
CImg Error : 'gm.exe' is not recognized as an internal or external command,
我是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 本机处理,不需要与外部库链接。
我知道这个问题很老,但我在一个项目上一直遇到同样的错误,而不是在另一个项目上,这是谷歌上唯一的事情。
要摆脱它,您必须做两件事:
-
为适当的操作系统和架构安装动态 ImageMagick 库(32/64)。链接
-
我使用的是VisualStudio,字符集必须设置为"Unicode"。当我恢复为多字节字符集时,错误会再次出现。我想这与 CImg 处理字符串并错误比较它们的方式有关。
- 在函数内部的声明中初始化数组,并在外部使用它
- 从函数角度看ID到文件路径的内部与外部映射
- spdlog标头仅与外部fmt一起使用.spdlog错误:'内部':不是'fmt'
- 类内部和外部静态 constexpr 元组之间的差异
- 在 typedef 内部使用 const 关键字和在 typedef 外部使用 const 关键字之间有区别吗?
- CMake 外部和内部静态库的循环依赖关系
- 当使用lambda进行变量的复杂初始化时,如何处理从内部抛出的lambda外部异常
- 在命名空间内部还是外部实现 c++ 函数?
- C++:在"try"外部创建的类型会导致错误,但在内部不会
- 'cmake'不被识别为内部或外部命令 - 北极星
- C++:在循环内部或外部声明一个向量
- 如何使结构内部的可变参数模板可以在外部访问?
- exe文件不被识别为内部或外部命令,可操作的程序或批处理文件在C++
- 初始化向量的向量(外部向量和内部向量)
- G++ 自定义任务在外部终端中打开,与 VS 代码内部终端
- 使用 java 类在 C++ 内部导入外部 jarfile
- 用相同的参数将内部和外部构造函数分开
- 有什么区别:在命名空间 yyy 外部和内部使用 namespae xxx?
- 参数内部和外部的指针
- 类型是否只有内部/外部链接以外的"链接"?