Untitled

 avatar
Fry
plain_text
5 months ago
632 B
20
Indexable
public async Task<Bitmap> GetBitmapFromUrlAsync(string imageUrl)
    {
        using (HttpClient client = new HttpClient())
        {
            try
            {
                byte[] imageBytes = await client.GetByteArrayAsync(imageUrl);
                using (MemoryStream ms = new MemoryStream(imageBytes))
                {
                    Bitmap bitmap = new Bitmap(ms);
                    return bitmap;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error downloading image: {ex.Message}");
                return null;
            }
        }
    }
Leave a Comment