Simple class to retrieve country flag by its country code. Archive contains normalized vector country flags (svg format) from different sources.
CountryFlags.zipnamespace Example
{
public static class CountryFlags
{
public static IEnumerable<string> AllFlagsResourceNames =>
Assembly.GetExecutingAssembly().GetManifestResourceNames().Where(r => r.Contains("CountryFlags.Images"));
public static string GetResourceName(string countryCode)
{
return $"Examle.CountryFlags.Images.{countryCode.ToLower()}.svg";
}
public static Stream GetFlagAsStream(string countryCode)
{
return Assembly.GetExecutingAssembly().GetManifestResourceStream(GetResourceName(countryCode));
}
public static byte[] GetFlagAsByteArray(string countryCode)
{
var stream = GetFlagAsStream(countryCode);
byte[] result = new byte[stream.Length];
stream.Read(result, 0, result.Length);
return result;
}
}
}
No comments:
Post a Comment