Magick++ Segmentation Fault
Posted: 2010-09-20T00:49:06-07:00
Hi there,
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:
However, when I tried to implement it in a bigger project, I got segmentation fault error. Below is the code that won't work on my computer.
When I tried to trace through the source code, I found that the error occurred at
I really don't know what is wrong with the source code, as the main logic is basically the same as the first source code that works perfectly. Is there any problem with putting the source code into the class?
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.
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.