-
Notifications
You must be signed in to change notification settings - Fork 375
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...
})Or if you need the dimensions and source: `Success(
.Error(exception =>
{
// your code here...
})
.Into(_imageView);Note: these callback is also available with width and height. In this case the callback is an Action<int, int>.
There is a third callback: when image loading process finished. Whatever the result this method will be called:
ImageService.LoadUrl(urlToImage)
.Finish(workScheduled =>
{
// your code here...
})
.Into(_imageView);It is possible to define placeholders while image is loading or when an error occured
ImageService.LoadUrl(urlToImage)
.LoadingPlaceholder("loading.png") // by default placeholders load from file
.ErrorPlaceholder("http://mydomain.com/error.png", ImageSource.Url) // but they can also load from a URL
.Into(_imageView);If your download failed, or something wrong happened you can automatically retry. Here if loading from the URL failed then we will try 3 more times with a 200ms interval between each trial.
ImageService.LoadUrl(urlToImage)
.Retry(3, 200)
.Into(_imageView);If you want to downsample the image so it takes less memory then you can define your new width/height. Note: it will keep aspect ratio even if you give crazy values to width/height and it can only downscale.
// you can only give one value since we keep aspect ratio
ImageService.LoadUrl(urlToImage).DownSample(width: 150).Into(_imageView);Transformations are possible too:
ImageService.LoadUrl(urlToImage)
.Transform(new CropCircleTransformation())
.Transform(new GrayscaleTransformation())
.Into(imgDisplay);Original image, prior to transformation, is cached to disk. Transformed image is cached in memory. If the same image, with same transformations is requested then it will be loaded from memory. For more information about transformations open our sample project.