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
It says it is not a valid parameter for the setpixel.

Can someone show me how to create a full color structure given an int x, which is between 0 and 255. I will fill in x for each value(rgb) so I get a grey scale

Share this post


Link to post
Share on other sites
CWIZO    118
System.Drawing.Color color = System.Drawing.Color.FromArgb ( r, g, b );


where r, g and b are integers ranging from 0 to 255.

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
lenny4422    140
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
Washu    7829

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
Yes! I fiddled with the algorithm, and the intiation of the bitmap, and now everything is running smoothly! Thanks everyone! I guess this is the end of this thread.

Sagar Indurkhya :)

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