I'm trying to export an image from raw pixel data into a RGBA PNG using the Magick++ library.
However, I'm getting a strange error when I'm attempting to run it:
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
This is the relevant code part (I omitted filling the pixel vector, but that doesn't change anything):
#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");
}
Compilation with:
g++ --std=c++11 -O0 -g3 -ggdb3 -D_GLIBCXX_DEBUG -Wall test.cpp -o test `Magick++-config --cppflags --cxxflags --ldflags --libs`
Aucun commentaire:
Enregistrer un commentaire