| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 下载用户头像 |
| | | /// </summary> |
| | | /// <param name="imageUrl"></param> |
| | | /// <param name="ignoreCache">忽略缓存</param> |
| | | /// <param name="regionUrl">指定服务器域名,传空为使用当前用户地址</param> |
| | | /// <returns></returns> |
| | | public byte[] DownImageByImageUrl(string imageUrl, bool ignoreCache = false) |
| | | { |
| | | try |
| | | { |
| | | if (string.IsNullOrEmpty(imageUrl)) return null; |
| | | |
| | | byte[] imageBytes; |
| | | if (!ignoreCache && Exists(imageUrl)) |
| | | { |
| | | //本地有缓存 |
| | | imageBytes = ReadFile(imageUrl); |
| | | } |
| | | else |
| | | { |
| | | //下载 |
| | | imageBytes = HttpUtil.HttpsDownload(imageUrl); |
| | | if (imageBytes != null) |
| | | { |
| | | //保存到本地 |
| | | WriteFileByBytes(imageUrl, imageBytes); |
| | | } |
| | | |
| | | } |
| | | return imageBytes; |
| | | } |
| | | catch |
| | | { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | |
| | | #endregion |
| | | } |
| | | } |