Page 1 of 1

Magick++ does not create expected background color

Posted: 2010-03-22T14:59:17-07:00
by rich2449
As far as I can tell from the documentation the following code should produce a black image, with the red pixel in the center.

Code: Select all

	// create image with dimensions of 320x200 pixels, set background color to black	
	Magick::Image image( Magick::Geometry( 320, 200 ), Magick::Color( 0,0,0 ) );

	// set pixel roughly in middle to red
	image.pixelColor( 160, 100, Magick::Color( "red" ) );

	// write out as png image
	image.write( "test.png" );
However the image produced has a light grey background color, RGB(205,205,205).

I'm sure I'm missing something here.... but why is the background not black, as specified in the constructor to the image object?

Thanks in advance, Rich

Re: Magick++ does not create expected background color

Posted: 2010-03-22T15:14:35-07:00
by fmw42
try setting the background color

Re: Magick++ does not create expected background color

Posted: 2010-03-22T15:17:08-07:00
by rich2449
Setting the background color via

Code: Select all

image.backgroundColor( Magick::Color( 0,0,0 ) );
makes no difference, the background still comes out being 205,205,205?

Re: Magick++ does not create expected background color

Posted: 2010-03-22T15:18:53-07:00
by fmw42
I don't use APIs, only command line, but this topic might help --- see viewtopic.php?f=6&t=15832#p56657

Re: Magick++ does not create expected background color

Posted: 2010-03-22T15:37:58-07:00
by rich2449
Ah ha! Thank you for the link.

It would seem that the image constructor does not set the background color, what color it does set I have no idea. The documentation just states "Construct a blank image canvas of specified size and color". Can anyone shed any light on what "color" is set with this constructor?

Adding the lines:

Code: Select all

	image.backgroundColor( Magick::Color( 0,0,0 ) );
	MagickCore::SetImageBackgroundColor( image.image() );
created the desired black background. Thanks to all for helping.