{"id":482,"date":"2017-01-24T14:58:42","date_gmt":"2017-01-24T14:58:42","guid":{"rendered":"https:\/\/ibex.tech\/windows-iot\/?p=482"},"modified":"2017-01-24T14:58:42","modified_gmt":"2017-01-24T14:58:42","slug":"color-general","status":"publish","type":"post","link":"https:\/\/ibex.tech\/csharp\/uwp-programming-in-c\/color\/color-general","title":{"rendered":".Color General"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Convert RGB colour value to Brush<br> <\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>using Windows.UI;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\t\/\/************************************************\n\t\/\/************************************************\n\t\/\/********** CONVERT RGB TO BRUSH COLOR **********\n\t\/\/************************************************\n\t\/\/************************************************\n\tprivate Brush ConvertRgbHexToBrushColor(string hex)\n\t{\n\n\t\ttry\n\t\t{\n\t\t\tif (hex.StartsWith(\"#\"))\n\t\t\t\thex = hex.Substring(1);\n\n\t\t\tif (hex.Length != 6) throw new Exception(\"Color not valid\");\n\n\t\t\treturn new SolidColorBrush(ColorHelper.FromArgb(\n\t\t\t\t0xff,\n\t\t\t\tbyte.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber),\n\t\t\t\tbyte.Parse(hex.Substring(2, 2), System.Globalization.NumberStyles.HexNumber),\n\t\t\t\tbyte.Parse(hex.Substring(4, 2), System.Globalization.NumberStyles.HexNumber)));\n\t\t}\n\t\tcatch (Exception )\n\t\t{\n\t\t\treturn new SolidColorBrush(ColorHelper.FromArgb(0xff, 0xff, 0xff, 0xff));\n\t\t}\n\t}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Convert RGB color value to Color<br><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>using Windows.UI;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\t\/\/******************************************\n\t\/\/******************************************\n\t\/\/********** CONVERT RGB TO COLOR **********\n\t\/\/******************************************\n\t\/\/******************************************\n\tprivate Color ConvertRgbHexToColor(string hex)\n\t{\n\t\t\n\t\ttry\n\t\t{\n\t\t\tif (hex.StartsWith(\"#\"))\n\t\t\t\thex = hex.Substring(1);\n\n\t\t\tif (hex.Length != 6) throw new Exception(\"Color not valid\");\n\n\t\t\treturn Color.FromArgb(\n\t\t\t\t0xff,\n\t\t\t\tbyte.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber),\n\t\t\t\tbyte.Parse(hex.Substring(2, 2), System.Globalization.NumberStyles.HexNumber),\n\t\t\t\tbyte.Parse(hex.Substring(4, 2), System.Globalization.NumberStyles.HexNumber));\n\t\t}\n\t\tcatch (Exception )\n\t\t{\n\t\t\treturn Color.FromArgb(0xff, 0xff, 0xff, 0xff);\n\t\t}\n\t}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Convert RGB colour value to Brush Convert RGB color value to Color<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[91],"tags":[],"class_list":["post-482","post","type-post","status-publish","format-standard","hentry","category-color"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/482","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/comments?post=482"}],"version-history":[{"count":0,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/482\/revisions"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/media?parent=482"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/categories?post=482"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/tags?post=482"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}