c++ - Magick++ Error when reading BLOB into Image -


i'm trying export image raw pixel data rgba png using magick++ library.

however, i'm getting strange error when i'm attempting run it:

terminate called after throwing instance of 'magick::errorcorruptimage'   what():  test: unexpected end-of-file `': no such file or directory @ error/rgb.c/readrgbimage/229 aborted 

this relevant code part (i omitted filling pixel vector, 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` 

your example works if using q8 version of imagemagick. seems using q16 version of imagemagick. latter uses 16 bits per pixel channel. using vector<unsigned char> 8 bits. advise switch vector<unsigned short> or use vector<unsigned char> twice current size. switch q8 version of imagemagick if don't need 16 bits per pixel channel.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -