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

Started by
8 comments, last by Sagar_Indurkhya 19 years, 9 months ago
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?
Advertisement
How do I create a color object, from a r,g,b value?
What's the exact error message?
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
You can remove the first paramater (alpha). When there are only 3 parameters (RGB), then the function will use 255 alpha automatically.
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
System.Drawing.Color color = System.Drawing.Color.FromArgb ( r, g, b );


where r, g and b are integers ranging from 0 to 255.
-----------------SloGameDev.net | My homepageQ:What does a derived class in C# tell to it's parent?A:All your base are belong to us!
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
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#.
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.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

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 :)

This topic is closed to new replies.

Advertisement