Using PixelSetColor()

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
rohitkrishna
Posts: 43
Joined: 2011-10-01T14:34:04-07:00
Authentication code: 8675308

Using PixelSetColor()

Post by rohitkrishna »

Hi everyone...

Iam trying to use PixelSetColor() in my program..i have a doubt ..can i give variables instead of numbers is the second argument like rgb(a,b,c) [in which r,g,b values are stored in a b,c] instead of rgb(0,255,0)...Iam attaching my code here...When i use variables its not working...

Code: Select all

a=0;
	while(a<v.n_sbimg)
	{
		modify_iterator=NewPixelRegionIterator(modify_wand,v.col[a],v.row[a],v.sbimg_wdt,v.sbimg_hgt);
		for(y=0;y<v.sbimg_hgt;y++)
		{
			modify_pixels = PixelGetNextIteratorRow(modify_iterator, &v.sbimg_wdt);
			for(x=0;x<v.sbimg_wdt;x++)
			{
				int t=loc(y,x,v.sbimg_wdt)+ a*v.sbimg_pxl;
				unsigned char r=new_data[t],g=new_data[t+1],b=new_data[t+2];
				PixelSetColor(modify_pixels[x],"rgb(r,g,b)"); // this function sets the color of pixel.
				PixelSyncIterator(modify_iterator);
			}
		}
	a++;
	}
Can anyone please help me..?
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Using PixelSetColor()

Post by el_supremo »

The problem is that you have to pass "rgb(a,b,c)" as a string so anything inside the string is not interpreted as variables.
But you could use sprintf to create the string and then pass that. e.g.

Code: Select all

char rgb_string[64];
.
.
.
            sprintf(rgb_string,"rgb(%d,%d,%d)",a,b,c);
            PixelSetColor(modify_pixels[x],rgb_string); // this function sets the color of pixel.
Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
rohitkrishna
Posts: 43
Joined: 2011-10-01T14:34:04-07:00
Authentication code: 8675308

Re: Using PixelSetColor()

Post by rohitkrishna »

el_supremo wrote:The problem is that you have to pass "rgb(a,b,c)" as a string so anything inside the string is not interpreted as variables.
But you could use sprintf to create the string and then pass that. e.g.

Code: Select all

char rgb_string[64];
.
.
.
            sprintf(rgb_string,"rgb(%d,%d,%d)",a,b,c);
            PixelSetColor(modify_pixels[x],rgb_string); // this function sets the color of pixel.
Pete
Thank you...very much....U really made my work going.....
Post Reply