Page 1 of 1

[SOLVED] First time Magick++ user with color problems

Posted: 2009-05-06T12:55:22-07:00
by NarcoticV
Hey everyone,

This is my first time using IM. I am trying to create a GIF image using Magick++, but I am having difficulties getting the colors right. Whatever I do, it seems that the file that is created only has a very limited number of colors. I am probably missing something here, so any help would be appreciated!

The following code is supposed to make a 73*14 GIF image (works), make the background black (works), and draw a number of pixels with a gradient of R/G combinations (which are stored in the array colors[16][16], where the two array indices represent values for red and green).

Code: Select all

Color colors[16][16]; //all tints of r/g in an array

		//generate all the array's colors for the visible palette in the image:
		int r = 0;
		int g = 0;
		while(r<16)
		{
			while(g<16)
			{
				colors[r][g] = ColorRGB((double)(r*16), (double)(g*16), 0);
				g++;
			}

			r++;
			g = 0;
		}

		Image result; //make an image
		result.depth(24); //bit depth
		result.size( Geometry(73, 14) ); //image size
		result.backgroundColor( colors[0][0] ); //background color
		result.compressType( NoCompression ); //No compression enabled
		result.gifDisposeMethod(1); //fastest frame disposal (none)

		int x = 0;
		int y = 1;
		r = g = 0;

		//display a list of all important colors
		while(r<16)
		{
			while(g<16)
			{
				result.pixelColor(x, y, colors[r][g]);				

				x++; //next position
				if(x >= 73) //end of line
				{
					x = 0;
					y++;
				}
				g++;
			}

			g = 0;
			r++;
		}		

		//construct the filename
		//string str1 = LCCUBEANIMATION_PATHPRE; //add the directory to the filename
		string str1 = "";
		str1.append(filename);
		str1.append(LCCUBEANIMATION_PATHPOSTGIF); //add the filetype to the filename

		result.write(str1); //attempt to write the image
Instead of outputting all these nice combinations, the resulting GIF file looks quite terrible. Only 4 colors: black, bright green, bright red and bright yellow are shown, so apparantly the colors are quantized somehow when saving the image. What am I doing wrong?

I am using Visual C++ 2008 Express, with a precompiled binary release of ImageMagick that was installed in 16-bit dll mode.

Re: First time Magick++ user with color problems

Posted: 2009-05-06T14:02:45-07:00
by NarcoticV
Ah, I see. Turns out I didn't read the documentation very accurately and didn't realize that the RGB values in ColorRGB are between 0.0 and 1.0. :? Sorry for the unneccesary post.