Example #1
0
        public static void DisplayNetworkImage(Uri uri, ImageView imgView, PointF size = null, bool cache = true)
        {
            var options = new DisplayImageOptions.Builder()
                          .CacheInMemory(cache)
                          .CacheOnDisk(cache)
                          .ConsiderExifParams(true)
                          .BitmapConfig(Bitmap.Config.Rgb565)
                          .DelayBeforeLoading(0)
                          .Build();

            var targetSize = (size == null) ? null : new ImageSize((int)Math.Round(size.X), (int)Math.Round(size.Y));

            NonViewAware nonViewAware = new NonViewAware(targetSize, ViewScaleType.FitInside);

            Action <string, View, Bitmap> loadingComplete = (imageUri, v, loadedImage) => {
                using (var h = new Handler(Looper.MainLooper))
                {
                    h.Post(() => {
                        try
                        {
                            imgView.SetImageBitmap(loadedImage);
                        }
                        catch (Exception ex)
                        {
                            Utils.WriteLog("DisplayNetworkImage", ex.Message);
                        }
                    });
                }
            };

            LoadingListener listener = new LoadingListener(loadingComplete);

            ImageLoader.Instance.DisplayImage(uri.ToString(), nonViewAware, options, listener);
        }
Example #2
0
        public static void DisplayDiskImage(string imgPath, ImageSwitcher imgSwitch, PointF size = null, bool cache = true)
        {
            if (!System.IO.File.Exists(imgPath))
            {
                Utils.WriteLog("Immagine non esistente - " + imgPath);
                return;
            }

            Uri uri = new Uri(imgPath);

            if (cache)
            {
                Java.IO.File cacheFile = ImageLoader.Instance.DiskCache.Get(uri.ToString());

                if (cacheFile != null)
                {
                    Java.IO.File file = new Java.IO.File(imgPath);

                    if (file.LastModified() > cacheFile.LastModified())
                    {
                        ImageLoader.Instance.DiskCache.Remove(uri.ToString());
                    }
                }
            }

            var options = new DisplayImageOptions.Builder()
                          .CacheInMemory(false)
                          .CacheOnDisk(cache)
                          .ConsiderExifParams(true)
                          .BitmapConfig(Bitmap.Config.Rgb565)
                          .DelayBeforeLoading(0)
                          .Build();

            var targetSize = (size == null) ? null : new ImageSize((int)Math.Round(size.X), (int)Math.Round(size.Y));

            //ImageLoader.Instance.DisplayImage();
            NonViewAware nonViewAware = new NonViewAware(targetSize, ViewScaleType.FitInside);

            Action <string, View, Bitmap> loadingComplete = (imageUri, v, loadedImage) => {
                using (var h = new Handler(Looper.MainLooper))
                {
                    h.Post(() => {
                        try
                        {
                            imgSwitch.SetImageDrawable(new BitmapDrawable(loadedImage));
                        }
                        catch (Exception ex)
                        {
                            Utils.WriteLog("DisplayDiskImage", ex.Message);
                        }
                    });
                }
            };

            LoadingListener listener = new LoadingListener(loadingComplete);

            ImageLoader.Instance.DisplayImage(uri.ToString(), nonViewAware, options, listener);
        }