Magick++ does not create expected background color

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
rich2449
Posts: 11
Joined: 2010-03-18T11:34:10-07:00
Authentication code: 8675308

Magick++ does not create expected background color

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Magick++ does not create expected background color

Post by fmw42 »

try setting the background color
rich2449
Posts: 11
Joined: 2010-03-18T11:34:10-07:00
Authentication code: 8675308

Re: Magick++ does not create expected background color

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Magick++ does not create expected background color

Post by fmw42 »

I don't use APIs, only command line, but this topic might help --- see viewtopic.php?f=6&t=15832#p56657
rich2449
Posts: 11
Joined: 2010-03-18T11:34:10-07:00
Authentication code: 8675308

Re: Magick++ does not create expected background color

Post 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.
Post Reply