I am new to using ImageMagick as image processing library and really need your help regarding the segmentation fault error when using the Magick++ Library for C++.
Previously, I developed a simple application used to test the magick++ library, and it worked successfully. Below is the simple source code I created:
Code: Select all
#include <cstdlib>
#include <Magick++.h>
using namespace std ;
using namespace Magick ;
int main ( int argc , char** argv )
{
Geometry g ( 100 , 100 ) ;
Color c ( MaxRGB , MaxRGB , MaxRGB , 0 ) ;
Magick::Image image ( g , c ) ;
for ( int x = 20 ; x <= 80 ; x ++ )
image.pixelColor ( x , 50 , Color ( 0 , 0 , 0 , 0 ) ) ;
image.magick ( "png" ) ;
image.write ( "/path_to_image/test.png" ) ;
return 0 ;
}
Code: Select all
#include "signaturewriter.h"
namespace util
{
SignatureWriter::SignatureWriter ( int width , int height , string pixel )
{
this -> _width = width ;
this -> _height = height ;
this -> _pixel = pixel ;
}
void SignatureWriter::writeToStorage ( string path )
{
Geometry g ( this -> _width , this -> _height ) ;
Color c ( MaxRGB , MaxRGB , MaxRGB , 0 ) ;
Magick::Image image ( g , c ) ;
for ( int h = 0 ; h < this -> _height ; h ++ )
{
for ( int w = 0 ; w < this -> _width ; w ++ )
{
int index = ( ( this -> _width ) * h ) + w ;
if ( ( this -> _pixel ) [ index ] == '1' )
image.pixelColor ( w , h , Color ( 0 , 0 , 0 , 0 ) ) ;
}
}
image.magick ( "png" ) ;
image.write ( path ) ;
}
}
Code: Select all
Magick::Image image ( g , c ) ;
Thanks in advance for your great help...
FYI, when I tried to move the source code of the magick++ in the bigger project one to the main function, it works as expected.