Reputation: 35
Using CImg: I read here that you can change an individual pixel's RGB data like this:
CImg<float> img("filename.jpg");
// Change the (100,200) pixel to Red.
img(100,200,0,0) = 255; //R
img(100,200,0,1) = 0; //G
img(100,200,0,2) = 0; //B
but img(100, 200, 0, 0)
returns the type unsigned char *
, which is obviously not a variable as the above snippet implies. When I run the above code, I get "error C2106: '=' : left operand must be l-value" in my build output.
A potential solution would be to use a different version of the CImg
constructor, which takes raw pixel data as its first parameter, but I can't find any information on how to format the data before running it through the constructor - the first parameter is describes as a template in line 9671 of CImg.h.
Any help would be greatly appreciated; I've been at this for a while.
Upvotes: 1
Views: 5752
Reputation: 970
You can use the function draw_point
.
From the reference manual:
CImg& draw_point ( const int x0, const int y0, const int z0, const tc ∗const color, const float opacity = 1 )
Upvotes: 0
Reputation: 41
The expression img(100,200,0,0)
is not a unsigned char*
but a unsigned char&
which makes a huge difference. Of course you can write img(100,200,0,0) = value
without any problems (except if your img
variable is const
), I use it all the time.
Note also that the third argument can be omitted in your case, as it is always 0
, so you can write img(x,y,0)=255; img(x,y,1)=1; img(x,y,2)=1;
.
Look at the examples provided in the CImg package, you will see that many code uses the CImg<T>::operator()
like this. Hopefully !
Upvotes: 1