public static ImageLoader GetUserIcon (string email, int size, Xwt.Screen screen = null) { if (screen == null) { screen = Xwt.Desktop.PrimaryScreen; } //only support integer scaling for now var scaleFactor = (int) screen.ScaleFactor; size = size * scaleFactor; var hash = GetMD5Hash (email); string key = hash + "@" + size + "x" + size; if (scaleFactor != 1) { key += "x" + scaleFactor; } ImageLoader loader; if (!gravatars.TryGetValue (key, out loader) || (!loader.Downloading && loader.Image == null)) { var cacheFile = UserProfile.Current.TempDir.Combine ("Gravatars", key); string url = "https://www.gravatar.com/avatar/" + hash + "?d=404&s=" + size; gravatars[key] = loader = new ImageLoader (cacheFile, url, scaleFactor); } return loader; }
public static ImageLoader GetUserIcon (string email, int size) { string key = email + size; ImageLoader img; if (!userIcons.TryGetValue (key, out img)) { var md5 = System.Security.Cryptography.MD5.Create (); byte[] hash = md5.ComputeHash (Encoding.UTF8.GetBytes (email.Trim ().ToLower ())); StringBuilder sb = new StringBuilder (); foreach (byte b in hash) sb.Append (b.ToString ("x2")); string url = "http://www.gravatar.com/avatar/" + sb.ToString () + "?d=mm&s=" + size; userIcons [key] = img = new ImageLoader (url); } return img; }