Page 1 of 1

Using PixelSetColor()

Posted: 2012-01-26T21:09:42-07:00
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..?

Re: Using PixelSetColor()

Posted: 2012-01-27T07:41:10-07:00
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

Re: Using PixelSetColor()

Posted: 2012-01-27T10:59:38-07:00
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.....