Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

system.Drawing vs Maui.Graphics; From.Argb gives different output

So I am using .NET Maui and came across the following problem.
I want to use .FromArgb but in Maui. Originally I was using System.Drawing.Color, but using Maui. Graphics.Color gives a different result:

//Color (example color)
int KeyColor = -16777088;

//system.Drawing way:
var forgroundColor = System.Drawing.Color.FromArgb(KeyColor);
//Output: "{Name=ff000080, ARGB=(255, 0, 0, 128)}"

//Maui.Graphics way (I have to use ToString cuz FromArgb needs an string):
var forgroundColorMaui = Microsoft.Maui.Graphics.Color.FromArgb(KeyColor.ToString());
//Output: Red=0, Green=0, Blue=0, Alpha=1

So I want to use the output from system.drawing but then in the Maui.Graphics. I dont know why the outputs are different. Anyone got an idea? Thanks you!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Take a look at the documentation for the method:

Color.FromArgb from a string-based hexadecimal value in the form "#AARRGGBB" or "#RRGGBB" or "#ARGB" or "RGB", where each letter corresponds to a hexadecimal digit for the alpha, red, green, and blue channels.

So we see the Maui version is not the same as the System.Drawing version and expects the input formatted in a different way.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading