public static BitmapImage GetImage(this ISleeve sleeve) { if (sleeve == null) { return(null); } BitmapImage image = null; using (var memoryStream = new MemoryStream(sleeve.ImageData)) { memoryStream.Position = 0; image = new BitmapImage(); image.BeginInit(); image.CacheOption = BitmapCacheOption.OnLoad; try { image.StreamSource = memoryStream; image.EndInit(); } catch (Exception ex) { throw new SleeveException($"Error loading deck sleeve for {sleeve.Name}, the image is invalid.", ex); } if (image.CanFreeze) { image.Freeze(); } } return(image); }
public static string ToString(ISleeve sleeve) { if (sleeve == null) { return(null); } switch (sleeve.Source) { case SleeveSource.User: return("custom:" + sleeve.Name + ":" + Convert.ToBase64String(sleeve.ImageData)); case SleeveSource.Game: return("game:" + sleeve.Name + ":" + sleeve.GameId.ToString()); case SleeveSource.OCTGN: return("octgn:" + sleeve.Name + ":"); default: throw new InvalidOperationException($"Can't use SleeveSource.{sleeve.Source}, it hasn't been implemented."); } }