下载正在缓存的图像并在我的imageview中显示

时间:2017-03-29 17:37:23

标签: xamarin

我需要使用Imageview下载保存在缓存中的图像,以某种方式让我以简单的方式进行操作?

我可以下载更多未保存在缓存中的下载文件

private Bitmap GetImageBitmapFromUrl(string url)
    {
        Bitmap imageBitmap = null;

        using (var webClient = new WebClient())
        {
            try
            {
                var imageBytes = webClient.DownloadData(url);
                if (imageBytes != null && imageBytes.Length > 0)
                {
                    imageBitmap = BitmapFactory.DecodeByteArray(imageBytes, 0, imageBytes.Length);
                }
            }
            catch
            {

            }
        }

        return imageBitmap;
    }

    //-----------

        **Show image**
        var imageBitmap = GetImageBitmapFromUrl("URL");
        imageView.SetImageBitmap(imageBitmap);

2 个答案:

答案 0 :(得分:0)

Android:使用imageView.SetImage(uri)find here

iOS:SDWebImage find here

答案 1 :(得分:0)

https://github.com/luberda-molinet/FFImageLoading

示例: -

ImageService.Instance.LoadUrl(urlToImage)
                .Retry(3, 200)
                .DownSample(300, 300)
                .Transform(new CircleTransformation())
                .Transform(new GrayscaleTransformation())
                .LoadingPlaceholder(Config.LoadingPlaceholderPath, ImageSource.ApplicationBundle)
                .ErrorPlaceholder(Config.ErrorPlaceholderPath, ImageSource.ApplicationBundle)
.Into(_imgDisplay);