picture->SetPixel(x_loc, y_loc, System::Drawing::Color::FromArgb(255,color,color,color));
[.net] Having trouble with System.Drawing.Color
I have some code that goes like this:
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?
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
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.
where r, g and b are integers ranging from 0 to 255.
btw, i am using managed C++.
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
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#.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement