Page 1 of 1

Getting a bunch of pixels leads me to segmentation fault...

Posted: 2017-04-20T15:14:51-07:00
by Airon65
This simple code:

Code: Select all

Magick::Image *imagePtr = new Magick::Image( "images/horse.jpg" );
Magick::Pixels view( *imagePtr );
Magick::Quantum *pixels = view.get( 0, 0, imagePtr->columns(), imagePtr->rows() );
unsigned int r = 255 * QuantumScale * ( *( pixels + 0 ) );
gives me segmentation fault. What do I do wrong here? It works only if I use const:

Code: Select all

const Magick::Quantum *pixels = view.getConst( 0, 0, imagePtr->columns(), imagePtr->rows() );
unsigned int r = 255 * QuantumScale * ( *( pixels + 0 ) );
but I need to modify some of those pixels so it shouldn't be const in my case. What's wrong with my code?

ImageMagick 7.0.5-2 Q16 x86_64 2017-03-11

Re: Getting a bunch of pixels leads me to segmentation fault...

Posted: 2017-04-21T06:34:31-07:00
by Airon65
But according to this article: https://www.imagemagick.org/Magick++/Pixels.html all should work fine but it doesn't

Re: Getting a bunch of pixels leads me to segmentation fault...

Posted: 2017-04-21T06:37:40-07:00
by snibgo
Again, to get the best help, I suggest you post a complete program, not merely a fragment. As your program reads an image file, also post that image.