【发布时间】:2020-03-17 18:41:57
【问题描述】:
我编写了一个读取、添加噪声和保存图像的 C++ 程序。我可以将图像保存为 .bmp,但是当尝试将图像保存为 .png 时,会弹出错误消息 ...除非启用 libMagick++,否则无法保存文件“noisy-canon.png”
在下面查看我的代码
#include <iostream>
#include <algorithm>
#include <vector>
#include <Magick++.h>
#include <CImg.h>
using namespace std;
using namespace cimg_library;
int main()
{
//image file
CImg<unsigned char> image("milla.png");
image.noise(5,2);
image.save_magick("noisy-canon.png");
CImgDisplay main_disp(image, "Image with Pepper noise",0);
while (!main_disp.is_closed())
{
main_disp.wait();
}
getchar();
return 0;
}
我也尝试使用 save_cimg()。它创建一个文件,错误提示
...除非启用 zlib,否则无法将压缩数据保存在文件“noisy_canon.png”中,将其保存为未压缩。
下面是我的代码;
(...)
image.save_cimg("noisy_canon.png",1);
(...)
以下尝试均未成功;
//above cimg.h "this gives error"
#define cimg_use_png
#include <CImg.h>
//tried below cimg.h "no error, but doesn't work"
#include <CImg.h>
#define cimg_use_png
提前致谢
【问题讨论】:
-
我不是magick++的用户,让我们从逻辑上看一下。要么 1)您使用的 magick++ 版本使用
#ifdef为 false 的 zlib 代码存根,或者 2)magick++ 在运行时找不到 zlib 动态链接库或插件,或者 3)您有调用一个函数来自己加载 zlib 库/插件。这 3 种情况最有可能发生。 -
@ThomasSablik...我已经编辑了这个问题。回顾一下
-
@PaulMcKenzie...我会检查您的建议...谢谢
-
你为什么要使用 ImageMagick?只需安装
libpng和zlib就可以了。根本不要包含Magick++.h。
标签: c++ image-processing imagemagick cimg