Ffimageloading: Using LoadStream to cache a image generated in runtime.

Created on 3 Sep 2017  路  1Comment  路  Source: luberda-molinet/FFImageLoading

In IOS Im generating an image in runtime, in order to cache it on disk with FFImageLoading im doing the following:

TaskCompletionSource<Stream> imageTcs = new TaskCompletionSource<Stream>();
var stream = uimage.AsPNG().AsStream();
imageTcs.TrySetResult(stream);

var taskParams = ImageService.Instance.LoadStream(sct => imageTcs.Task);
taskParams = taskParams.BitmapOptimizations(false);
taskParams = taskParams.WithPriority(LoadingPriority.Low);
taskParams = taskParams.WithCache(FFImageLoading.Cache.CacheType.Disk);
taskParams = taskParams.CacheKey(name);

ImageService.Instance.LoadImage(task);

Now the question is if i want to load this image again from cache how do i do it?, i can't find a way to load an image, previously loaded as a stream.

Thank you for the attention.

Most helpful comment

I figured it out i just needed to use ImageService.Instance.Config.DiskCache.
AddToSavingQueueIfNotExistsAsync to add a byte array to the disk cache.

Use ImageService.Instance.Config.DiskCache.ExistsAsync(id) to see if it exists.

And finally ImageService.Instance.Config.DiskCache.TryGetStreamAsync(id) to get a stream with the bytes.

>All comments

I figured it out i just needed to use ImageService.Instance.Config.DiskCache.
AddToSavingQueueIfNotExistsAsync to add a byte array to the disk cache.

Use ImageService.Instance.Config.DiskCache.ExistsAsync(id) to see if it exists.

And finally ImageService.Instance.Config.DiskCache.TryGetStreamAsync(id) to get a stream with the bytes.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vlkam picture vlkam  路  21Comments

ManhDucIT picture ManhDucIT  路  22Comments

si-matthews picture si-matthews  路  37Comments

LeoJHarris picture LeoJHarris  路  22Comments

stopiccot picture stopiccot  路  17Comments