Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
HTML Hex to RGB without using System.Drawing C#
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { //By: Vaibhav J. //vsj.1987@live.in public class Program { public static void Main(string[] args) { string[] hexes ={ "#FFFFFF","#C0C0C0","00000000","#000080","#55F27F","#F45F78A"}; foreach(string hex in hexes) { int [] rgb = HexToRGB(hex); string ans = string.Join(",",rgb); Console.WriteLine(ans+"\n"); } } public static int[] HexToRGB(string hex) { if (hex.LastIndexOf("#") > -1) { hex = hex.Replace("#", ""); } //ignore the Opacity. ex: FF000000 => 000000 (remove FF) if(hex.Length>6) { int strt = hex.Length-6; hex = hex.Substring(strt, 6); } Console.WriteLine(hex); int _hex = int.Parse(hex, System.Globalization.NumberStyles.AllowHexSpecifier); Console.WriteLine("int convert = {0}", _hex); var r = _hex >> 16; var g = (_hex & 0x00FF00) >> 8; var b = _hex & 0x0000FF; return new int[] { r, g, b }; } } }
run
|
edit
|
history
|
help
0
asxsadaxsdf
sortowanie ( jaka )? wybor? confirm it!
Intuit // C# // listing_4.3 (StreamWriter // @"c:\Temp\output.txt")
Second minor int
asfdfsafasfsa
1.1 Basics: language constructs
c# hashset custom comparer
UriParts
xx
Enumeration