c++ - Magick++ 不读取图像

标签 c++ cmake magick++

在我的第一个 magick++ 项目中,我试图读取图像、旋转它并保存它。

这是来源:

#include <iostream>
#include <Magick++.h>
#include <stdio.h>

using namespace std; 
using namespace Magick; 

int main(int argc, char *argv[]) {
    if (argc < 3)
   {
       printf("Usage: %s <Input file> <Output file>", argv[0]);
        return 1;
   }

   try{
        printf("Opening... %s\n", argv[1]);
        Magick::Image image(argv[1]);

        printf("Rotating...\n");
        image.rotate(45);

        printf("Opening... %s\n", argv[2]);
        image.write(argv[2]);
   }

   catch( Exception &error_ ) 
    { 
      cout << "Caught exception: " << error_.what() << endl; 
      return 1; 
    } 
  return 0;
}

我用 cmake (->msvc) 编译程序。它基本上编译得很好,它只是抛出了很多这种形式的 C4251 警告:
"Magick::PathMovetoRel::_coordinates": class "std::vector<Magick::Coordinate,std::allocator<Magick::Coordinate>>" erfordert eine DLL-Schnittstelle, die von Clients von class "Magick::PathMovetoRel" verwendet wird [C:\Users\jfi\Desktop\Hints_Scripts\InsortAP_Toolbox\VSCode\IMhelloworld_cmake\build\IMHelloWorld.vcxproj]

还有一个 C4275 警告:
{
"resource": "/C:/Program Files/ImageMagick-7.0.9-Q8/include/Magick++/Exception.h",
"owner": "cmake-build-diags",
"code": "C4275",
"severity": 4,
"message": "class \"std::exception\" ist keine DLL-Schnittstelle und wurde als Basisklasse für die DLL-Schnittstelle class \"Magick::Exception\" verwendet [C:\\Users\\jfi\\Desktop\\Hints_Scripts\\InsortAP_Toolbox\\VSCode\\IMhelloworld_cmake\\build\\IMHelloWorld.vcxproj]",
"source": "MSVC",
"startLineNumber": 23,
"startColumn": 3,
"endLineNumber": 23,
"endColumn": 3
}

程序在读取图像时停止。它不会给出任何错误消息。
我可以为magick++添加一些冗长吗?

谢谢你的帮助!

最佳答案

从文档

Be sure to initialize the ImageMagick library prior to using the Magick++ library. This initialization is performed by passing the path to the ImageMagick DLLs (assumed to be in the same directory as your program) to the InitializeMagick() function call. This is commonly performed by providing the path to your program (argv[0]) as shown in the following example:

int main(int argc, char** argv)
{
InitializeMagick(*argv);


你没有调用 InitializeMagick

关于c++ - Magick++ 不读取图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60893168/

相关文章:

c++ - 使用 Magick++ 和 openMPI 编译 C++ 代码

c++ - Windows 10 屏幕坐标偏移 7

c++ - 是否可以在 Qt 中使用带下划线的字母作为键盘快捷键?

c++ - CARLA RGB相机传感器的输出格式是什么

visual-studio - 如何在目标之间创建人为的循环依赖

cmake - CPack 无法使用 AppleScript 调整磁盘镜像和音量图标

c++ - 来自 0.0.0.0 :32772 的意外套接字连接

c++ - CMakeList 关于 MySQL Connector c++ 8.0 配置

c++ - 无法使用 Magick++ 编译代码(库问题)

c++ - VS2010 中的 Magick++ - 未解析的外部符号