Sign in to follow this  
Sagar_Indurkhya

[.net] Having trouble with System.Drawing.Color

Recommended Posts

I have some code that goes like this:

picture->SetPixel(x_loc, y_loc, System::Drawing::Color::FromArgb(255,color,color,color));

where picture is a bitmap, x_loc and y_loc are the location of the pixels, and I am trying to specify a color, where the variable color is an int between 0 - 255. It says that System::Drawing::Color::FromArgb(255,color,color,color) is not correct. What is up with that?

Share this post


Link to post
Share on other sites
btw, i am using managed C++.


System::Drawing::Color pixelcolor = System::Drawing::Color::FromArgb(255,0,0);

picture->SetPixel(x_loc, y_loc, pixelcolor);


I know it is the line where I am setting the pixel.

Here are the values.

x_loc = 0;
y_loc = 0;

Still says I have invalid parameter

Share this post


Link to post
Share on other sites
If it says invalid parameter to setpixel, the only thing I could think of is that the method takes color as an int, and not a Color object. It would probably help if you post the signature of the setpixel method.

If it does take an int, try this:

System::Drawing::Color pixelcolor = System::Drawing::Color::FromArgb(255,0,0);

picture->SetPixel(x_loc, y_loc, pixelcolor.ToArgb( ) );


Hope my syntax is correct, I use C#.

Share this post


Link to post
Share on other sites

System::Drawing::Bitmap __gc * b = new System::Drawing::Bitmap(2,3);
System::Drawing::Color c = System::Drawing::Color::FromArgb(255, 0, 0);
b->SetPixel(0, 0, c);


The above code works fine for me.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this