39 lines
967 B
C#
39 lines
967 B
C#
using CoreGraphics;
|
|
using ImageIO;
|
|
|
|
namespace Blahblah.Library.Network;
|
|
|
|
public class ImageTask : DownloadTask<CGImage>
|
|
{
|
|
CGImageSource? imageSource;
|
|
|
|
public ImageTask(string url, string filePath, bool createImage, TaskCompletionSource<NetworkResult<bool>> source, CancellationToken token = default) : base(url, filePath, source, token)
|
|
{
|
|
if (createImage)
|
|
{
|
|
imageSource = CGImageSource.CreateIncremental(null);
|
|
}
|
|
}
|
|
|
|
protected override CGImage? Update(float progress)
|
|
{
|
|
if (imageSource == null || Data == null)
|
|
{
|
|
return null;
|
|
}
|
|
imageSource.UpdateData(Data, Data.Length >= (uint)expectedContentLength);
|
|
return imageSource.CreateImage(0, null!);
|
|
}
|
|
|
|
protected override void Disposing()
|
|
{
|
|
if (imageSource != null)
|
|
{
|
|
imageSource.Dispose();
|
|
imageSource = null;
|
|
}
|
|
base.Disposing();
|
|
}
|
|
}
|
|
|