Skip to content
This repository was archived by the owner on May 15, 2024. It is now read-only.
This repository was archived by the owner on May 15, 2024. It is now read-only.

[Bug] Unprecise UIColor conversion #1572

@tipa

Description

@tipa

Description

The precision of the color conversion for UIColor (and perhaps also for NSColor & other platforms) can be improved.

Steps to Reproduce

  1. Show UIColorPickerViewController and enter Display P3 Hex Color : #663399
  2. Get UIColor object from UIColorPickerViewController & call ToSystemColor on it
  3. Print Color as Hex string

Expected Behavior

#663399

Actual Behavior

#653299

This is because the CGColor has these components:
Red: 101.999986320734
Green: 50.9999969601631
Blue: 153.000021278858

With the current conversion, the values are rounded down:

return Color.FromArgb((int)(alpha * 255), (int)(red * 255), (int)(green * 255), (int)(blue * 255));

I think this would be a better conversion method:

return Color.FromArgb((int)Math.Round(alpha * 255), (int)Math.Round(red * 255), (int)Math.Round(green * 255), (int)Math.Round(blue * 255)); 

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions