Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
Developer Community or GitHub with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
I recently had a problem setting the background color (actually, creating a new view and setting that as the background view) on a UITableCellView.
When I did this (location.TicketColorRed etc are int values):
backgroundColor = UIColor.FromRGB(location.TicketColorRed, location.TicketColorGreen, location.TicketColorBlue);
I only got basic colors - passing in the RGB values for "Pink" gave white. Blue, Red, Yellow etc all worked ok, but nothing in between. Changing it to this:
backgroundColor = UIColor.FromRGB((float)location.TicketColorRed / 255, (float)location.TicketColorGreen /255, (float)location.TicketColorBlue / 255);
Gave me the colors I was expecting.
Unable to reproduce this bug.
Please provide a self-contained test case. The code in the runtime does exactly what you describe.
Created attachment 49 [details]
Project that shows the bug
The interesting file is the UIColorViewSource.cs
It specifies 2 cells. It returns the first one using the (int, int, int) version of FromRGB, and turns out white. The second converts to floats, divides by 255 and uses the (float, float, float) version of FromRGB, and returns a pinkish color as expected.
Basic colors seem to work (0, 0, 255) returns blue for both, but anything else as above returns the nearest basic color.
Okay, so the problem is this. There are two methods:
FromRGB (byte red, byte green, byte blue);
FromRGB (float red, float green, float blue);
Your code assumes that the compiler will choose the byte version, but it is choosing the float version and since all the values are outside the range of 0.0 to 1.0, they are getting clamped and you are not getting the results you expected.
My apologies - I am used to the .Net Color.FromARGB(int, int, int, int) methods, and didn't look close enough to see that these ones were bytes not ints - that explains it. Thank you.
I brought this bug up with the rest of the team and we all agreed that we should add FromRGB() and FromRGBA() overloads which take int arguments to prevent this kind of confusion in the future.
These API additions should make it into our next release (4.1)