• Advertisement
Sign in to follow this  

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

This topic is 4944 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
You can remove the first paramater (alpha). When there are only 3 parameters (RGB), then the function will use 255 alpha automatically.

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
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
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
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
Sign in to follow this  

  • Advertisement