Hello!

I have got an image and I want to change the value of his pixels and paste it into another image.
pixel(r,c): is actual pixel
b: changes from 0 to undetermined number, for example 100.
The problem comes for example when b=2;I think that the method doesn't understand the conversion FromArgb

System::Drawing::Color val;
	val.FromArgb(b);
	labelledImage->SetPixel(r,c,val);

Has anyone of you a solution for that problem or another idea so I can change the values of the pixels??

Thank you in advanced!

I haven't done this in a while, so I might be wrong, but try:

System::Drawing::Color val;
	val = RGB(0,0,b);
	labelledImage->SetPixel(r,c,val);

the method RGB doesn't exist, that's why I thought that maybe ToArgb would work.
anyway thank you for your proposal!

Did you #include <windows.h> ? The method RGB() should be declared in WinGDI.h which is included by windows.h

ok. I have made it. I have included <windows.h> and now it says

error C2440: '=' : cannot convert from 'COLORREF' to 'System::Drawing::Color'

in the line val = RGB(0,0,b);

I suppose that it returns another thing but I haven't work with windows.h before.
And another thing is that the variable is called b but it is not the rgB component of the colour.
What I am doing is labelling the image, so I want that each pixel has a number depending on the neighbors, but it is also right that I can make it with this value and only modify it.

Ok. My fault, I'm mixing things up...

Try:

System::Drawing::Color val;
	val = Color::FromArgb(b);
	labelledImage->SetPixel(r,c,val);

and see if it works better. If not: please post the errormessage

I have got these errors:

error C2653: 'Color' : is not a class or namespace name
error C3861: 'FromArgb': identifier not found

you know what happens? with the code I have there is no problem of compilation, there is one of execution, in a certain iteration it says that it is out of range and I think that it is because the conversion is wrong.

yeah... Color is a method from system.drawing, so my final solution would be:

System::Drawing::Color val;
val = System::Drawing::Color::FromArgb(b);
labelledImage->SetPixel(r,c,val);

your solution works good but know I have got the same error as before but in the next line. That means:

System::Drawing::Color val;
	val=System::Drawing::Color::FromArgb(v);
	[B]labelledImage->SetPixel(r,c,val);[/B]

when v=2 it says that this line is:
Error (in execution):An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in System.Drawing.dll

Let me tell you again that this isn't my field of expertise, but reading trough the documentation of SetPixel() and FromArgb(), I would conclude that you're making it to hard on yourself. Var 'v' is an ARGB-color?

Then simply doing this:

labelledImage->SetPixel(r,c,v);

should work.
No need for convertions to system::drawing::color

for example:

labelledImage->SetPixel(0,0, Image::rgb(255,0,0));

would make the first pixel red.

And if I'm wrong (which could very well be possible), here's a useful link

v is an integer, do you know if I could make a cast or something like this to change it to a Color, or another solution, how could I add 1 to a color I mean to this val that we have declared?

I don't have this method rgb, it is in the help but not in object browser that's why I can't apply it.
I have thought that I could label the image with this method that you said of RGB but assigning directly the value to the component, that is not what I wish but it is a solution and I think it could work.

Thank you for your help!!

RGB is a macro that takes 3 integer & returns a COLORREF & not a function, I believe. The link niek_e gave had rgb() & not RGB() So I am not sure whether I am right. Give it a try.

EDIT:
I refered MSDN RGB is indeed a macro Thats why you did not find it in object browser

This article has been dead for over six months. Start a new discussion instead.