Skip to content

Commit

Permalink
Fix LoadImages exceptions;
Browse files Browse the repository at this point in the history
  • Loading branch information
k-karuna committed May 24, 2021
1 parent 5fe7cdc commit a49d4d8
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions Services/ImageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Avalonia;
using Avalonia.Media.Imaging;
using Avalonia.Platform;
using Serilog;

namespace Atomex.Client.Desktop.Services
{
Expand All @@ -26,13 +27,20 @@ public ImageService()

public async void LoadImage(string url)
{
using WebClient wc = new();
await using Stream s = wc.OpenRead(url);
using System.Drawing.Bitmap bmp = new(s);
await using MemoryStream memory = new();
bmp.Save(memory, ImageFormat.Png);
memory.Position = 0;
Images[url] = new Bitmap(memory);
try
{
using WebClient wc = new();
await using Stream s = wc.OpenRead(url);
using System.Drawing.Bitmap bmp = new(s);
await using MemoryStream memory = new();
bmp.Save(memory, ImageFormat.Png);
memory.Position = 0;
Images[url] = new Bitmap(memory);
}
catch (Exception e)
{
Log.Error("Error during Loading Image");
}
}


Expand Down

0 comments on commit a49d4d8

Please sign in to comment.