-
Notifications
You must be signed in to change notification settings - Fork 377
iOS API
Easily load any image from any source.
Or from an URL. In this case the image is cached (by default 30 days but there is an optional TimeSpan so you can choose yours).
ImageService.LoadUrl(urlToImage).Into(_imageView);
when you want to load the image from a file or application bundle:
ImageService.LoadFile(fullPathToImage).Into(_imageView);
Remark: on iOS both ImageService.LoadFileFromApplicationBundle
and ImageService.CompiledResource
have the same effect as ImageService.LoadFile
.
In order to be notified when the image is successfully loaded or when there were errors:
ImageService.LoadUrl(urlToImage)
.Success(() =>
{
// your code here...
})
An overload exists to get dimensions and image source:
Success((size, loadingResult) => {})
The image source, of type LoadingResult, indicates if it was loaded from web, disk cache, memory cache, file, bundle, ...
.Error(exception =>
{
// your code here...
})
.Into(_imageView);
Finish callback is invoked when image loading process finished, whatever the result, success, failure or cancellation:
ImageService.LoadUrl(urlToImage)
.Finish(workScheduled =>
{
// your code here...
})
.Into(_imageView);
Argument workScheduled, of type IScheduledWork, indicates if it succeeded, failed or was cancelled.
It is possible to define placeholders while image is loading or when an error occured.
ImageService.LoadUrl(urlToImage)
.LoadingPlaceholder("loading.png") // placeholder loaded from file
.Into(_imageView);
By default placeholders are loaded from file but you can also specify the ImageSource (see below).
ImageService.LoadUrl(urlToImage)
.ErrorPlaceholder("http://mydomain.com/error.png", ImageSource.Url) // placeholder loaded from a URL
.Into(_imageView);
If your download failed, or something wrong happened, it can be automatically retried.
In this example, if loading from the URL failed then it will try 3 more times with a 200ms interval between each trial:
ImageService.LoadUrl(urlToImage)
.Retry(3, 200)
.Into(_imageView);
Take advantage of DownSample
to reduce memory usage from images. You can redefine width/height to the visible size. Users won't notice the difference but their phone memory will!
Even though method allows two optional parameters you should only provide either width or height. Aspect ratio will be kept based on provided value.
// In this example height will be calculated to match width while keeping the same aspect ratio.
ImageService.LoadUrl(urlToImage).DownSample(width: 150).Into(_imageView);
Transformations allow a whole new range of possibilities. Crop an image on the fly, change its colors, make it rounded... They are explained here.
Example:
// Image will have gray colors only.
ImageService.LoadUrl(urlToImage)
.Transform(new GrayscaleTransformation())
.Into(imgDisplay);