我正在尝试使用 Magick++ 库将图像从原始像素数据导出到 RGBA PNG。
但是,当我尝试运行它时遇到一个奇怪的错误:
terminate called after throwing an instance of 'Magick::ErrorCorruptImage'
what(): test: unexpected end-of-file `': No such file or directory @ error/rgb.c/ReadRGBImage/229
Aborted
这是相关的代码部分(我省略了填充像素向量,但这并没有改变任何东西):
#include <iostream>
#include <vector>
#include <ImageMagick/Magick++.h>
using namespace std;
int main(int argc, char *argv[]) {
Magick::InitializeMagick(*argv);
int rres, ires;
cin >> rres >> ires;
//RGBA
//rres: horiz. resolution, ires: vert. resolution
vector<unsigned char> image(rres * ires * 4);
Magick::Blob blob(&image[0], rres*ires*4);
Magick::Image img;
img.size(to_string(rres) + "x" + to_string(ires));
img.magick("RGBA");
img.read(blob);
img.write("out.png");
}
编译:
g++ --std=c++11 -O0 -g3 -ggdb3 -D_GLIBCXX_DEBUG -Wall test.cpp -o test `Magick++-config --cppflags --cxxflags --ldflags --libs`