当前位置: 首页>>代码示例>>C#>>正文


C# ImageView.SetImageRounded方法代码示例

本文整理汇总了C#中ImageView.SetImageRounded方法的典型用法代码示例。如果您正苦于以下问题:C# ImageView.SetImageRounded方法的具体用法?C# ImageView.SetImageRounded怎么用?C# ImageView.SetImageRounded使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ImageView的用法示例。


在下文中一共展示了ImageView.SetImageRounded方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetUrlDrawable

        private static void SetUrlDrawable(Context context, ImageView imageView, string url, Drawable defaultDrawable, long cacheDurationMs, IUrlImageViewCallback callback)
        {
            Cleanup(context);

            if (imageView != null)
                pendingViews.Remove(imageView);

            if (string.IsNullOrEmpty(url))
            {
                if (imageView != null)
                    imageView.SetImageDrawable(defaultDrawable);

                return;
            }

            var cache = UrlImageCache.Instance;
            var drawable = cache.Get(url);

            if (drawable != null)
            {
                if (imageView != null)
                    imageView.SetImageRounded((BitmapDrawable)drawable);
                if (callback != null)
                    callback.OnLoaded(imageView, drawable, url, true);
                return;
            }

            var baseDir = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
            var filename = System.IO.Path.Combine(baseDir, GetFilenameForUrl(url));
					
            var file = new System.IO.FileInfo(filename);
            if (file.Exists)
            {
                try
                {
                    if (cacheDurationMs == CACHE_DURATION_INFINITE || DateTime.UtcNow < file.LastWriteTimeUtc.AddMilliseconds(cacheDurationMs))
                    {
                        drawable = LoadDrawableFromFile(context, filename);
                        //var fis = context.OpenFileInput(filename);
                        //drawable = LoadDrawableFromStream(context, fis);
                        //fis.Close();

                        if (imageView != null)
                            imageView.SetImageDrawable(drawable);

                        cache.Put(url, drawable);

                        if (callback != null)
                            callback.OnLoaded(imageView, drawable, url, true);

                        return;
                    }
                    else
                    {
                        //TODO: File cache expired, refreshing
                        Android.Util.Log.Debug(LOGTAG, "File Cache Expired: " + file.Name);
                    }
                }
                catch (Exception ex)
                {
                    Android.Util.Log.Debug(LOGTAG, "File Cache Exception " + ex.ToString());
                }
            }

            if (imageView != null)
                imageView.SetImageDrawable(defaultDrawable);

            if (imageView != null)
                pendingViews.Put(imageView, url);

            //Check to see if another view is already waiting for this url so we don't download it again
            var currentDownload = pendingDownloads.Get(url);
            if (currentDownload != null)
            {
                if (imageView != null)
                    currentDownload.Add(imageView);

                return;
            }

            var downloads = new List<ImageView>();
            if (imageView != null)
                downloads.Add(imageView);

            pendingDownloads.Put(url, downloads);

            var downloaderTask = new AnonymousAsyncTask<string, string, BitmapDrawable>((p) =>
            {
                try
                {
                    var client = new System.Net.WebClient();
                    var data = client.DownloadData(url);

                    System.IO.File.WriteAllBytes(filename, data);

                    return LoadDrawableFromFile(context, filename);
                }
                catch (Exception ex)
                {
                    Android.Util.Log.Debug(LOGTAG, "Download Error: " + ex.ToString());
//.........这里部分代码省略.........
开发者ID:rrawla,项目名称:MonoDroid.UrlImageViewHelper,代码行数:101,代码来源:UrlImageViewHelper.cs


注:本文中的ImageView.SetImageRounded方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。