gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 10:04:39 24 4
gpt4 key购买 nike

在我的第一个 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com