Exemple #1
0
        public DiscordImage Download(DiscordCDNImageFormat format = DiscordCDNImageFormat.Any)
        {
            if (format != DiscordCDNImageFormat.Any && !AllowedFormats.Contains(format))
            {
                throw new NotSupportedException("Image format not supported. The supported formats for this endpoint are: " + string.Join(", ", AllowedFormats));
            }

            string url = Url;

            if (format != DiscordCDNImageFormat.Any)
            {
                url += "." + format.ToString().ToLower();
            }

            return(new DiscordImage((Bitmap) new ImageConverter().ConvertFrom(_client.GetByteArrayAsync(url).Result)));
        }
Exemple #2
0
        public DiscordImage Download(DiscordCDNImageFormat format = DiscordCDNImageFormat.Any)
        {
            if (format != DiscordCDNImageFormat.Any && SupportedFormats != null && !SupportedFormats.Contains(format))
            {
                throw new NotSupportedException("Image format not supported. Supported formats for this endpoint: " + string.Join(", ", SupportedFormats));
            }

            string extension = format == DiscordCDNImageFormat.Any ? "" : $".{format.ToString().ToLower()}";

            try
            {
                return(new DiscordImage((Bitmap) new ImageConverter().ConvertFrom(new HttpClient().GetByteArrayAsync(Url + extension).Result)));
            }
            catch
            {
                return(null);
            }
        }