Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

Commit

Permalink
调整加载图像的函数,使其可以取消、暂停和报告进度
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiichiamane committed Jun 5, 2020
1 parent 3514417 commit 0cd1d62
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions PixivFSUWP/Data/OverAll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,24 @@ public static async Task<string> GetDataUri(string Uri)
return string.Format("data:image/png;base64,{0}", Convert.ToBase64String((await DownloadImage(Uri)).ToArray()));
}

public static async Task<BitmapImage> LoadImageAsync(string Uri)
public static async Task<BitmapImage> LoadImageAsync(string Uri, ManualResetEvent PauseEvent = null, Func<long, long, Task> ProgressCallback = null)
=> await LoadImageAsync(Uri, CancellationToken.None, PauseEvent, ProgressCallback);

public static async Task<BitmapImage> LoadImageAsync(string Uri, CancellationToken CancellationToken, ManualResetEvent PauseEvent = null, Func<long, long, Task> ProgressCallback = null)
{
var toret = new BitmapImage();
using (var memStream = await DownloadImage(Uri))
using (var memStream = await DownloadImage(Uri, CancellationToken, PauseEvent, ProgressCallback))
await toret.SetSourceAsync(memStream.AsRandomAccessStream());
return toret;
}

public static async Task<WriteableBitmap> LoadImageAsync(string Uri, int Width, int Height)
public static async Task<WriteableBitmap> LoadImageAsync(string Uri, int Width, int Height, ManualResetEvent PauseEvent = null, Func<long, long, Task> ProgressCallback = null)
=> await LoadImageAsync(Uri, Width, Height, PauseEvent, ProgressCallback);

public static async Task<WriteableBitmap> LoadImageAsync(string Uri, int Width, int Height, CancellationToken CancellationToken, ManualResetEvent PauseEvent = null, Func<long, long, Task> ProgressCallback = null)
{
var toret = new WriteableBitmap(Width, Height);
using (var memStream = await DownloadImage(Uri))
using (var memStream = await DownloadImage(Uri, CancellationToken, PauseEvent, ProgressCallback))
await toret.SetSourceAsync(memStream.AsRandomAccessStream());
return toret;
}
Expand Down

0 comments on commit 0cd1d62

Please sign in to comment.