xamarin.Android ImageView 异步加载网络图片


     /// <summary>
        /// 异步获取文件流
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public async Task<Stream> GetFileStreamAsync(string url)
        {
            try
            {
                System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
                var fileStream = await client.GetStreamAsync(url);
                return fileStream;
            }
            catch (Exception ex)
            {
                throw new WebServiceException(ex.Message);
            }
        }
     private async void SetImage(string url)
        {var stream = await GetFileStreamAsync(url);
            var imageView = FindViewById<ImageView>(Resource.Id.iv_userphoto_mycenter_myprofile);
            imageView.SetImageBitmap(BitmapFactory.DecodeStream(stream));
        }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM