Azure 如何将图像下载到Xamarin.forms列表视图
我在列表视图中有一个图像url,点击列表视图后,图像应该下载到同一行。 如何在Xamarin.forms上实现?Azure 如何将图像下载到Xamarin.forms列表视图,azure,xamarin.forms,azure-storage-blobs,Azure,Xamarin.forms,Azure Storage Blobs,我在列表视图中有一个图像url,点击列表视图后,图像应该下载到同一行。 如何在Xamarin.forms上实现? 我从Azure blob中获得了图像我建议使用Xamarin Forms Listview和SQL和blob存储查看这篇博客文章。他们基本上使用SQL存储Blob存储中的图像,使用以下代码: public class AzureMediaStorageService : IMediaStorageService { private CloudBlobContainer Med
我从Azure blob中获得了图像我建议使用Xamarin Forms Listview和SQL和blob存储查看这篇博客文章。他们基本上使用SQL存储Blob存储中的图像,使用以下代码:
public class AzureMediaStorageService : IMediaStorageService
{
private CloudBlobContainer MediaContainer { get; set; }
public void InitializeStorage(string settings = null)
{
if (MediaContainer != null)
return;
if (string.IsNullOrEmpty(settings))
throw new ArgumentNullException(nameof(settings), "Azure Storage Media Service needs a connection string name as \"settings\" parameter");
var storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings[settings].ConnectionString);
var blobClient = storageAccount.CreateCloudBlobClient();
MediaContainer = blobClient.GetContainerReference("medias");
MediaContainer.CreateIfNotExists();
MediaContainer.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
}
public async Task<Uri> UploadBytesAsync(byte[] bytes, string uniqueId, MediaType mediaType)
{
var blockBlob = MediaContainer.GetBlockBlobReference(uniqueId);
blockBlob.Properties.ContentType = mediaType == MediaType.Picture ? "image/jpeg" : "video/mp4";
await blockBlob.UploadFromByteArrayAsync(bytes, 0, bytes.Length);
return blockBlob.Uri;
}
public async Task<byte[]> DownloadBytesAsync(Uri uri)
{
using (var httpClient = new HttpClient())
{
var response = await httpClient.GetAsync(uri, HttpCompletionOption.ResponseContentRead);
response.EnsureSuccessStatusCode();
return await response.Content.ReadAsByteArrayAsync();
}
}
public string GetSecureClientUploadUrl(string uniqueId, DateTimeOffset expirationDateTime)
{
if (expirationDateTime <= DateTimeOffset.Now)
throw new ArgumentOutOfRangeException(nameof(expirationDateTime), expirationDateTime, null);
var blob = MediaContainer.GetBlockBlobReference(uniqueId);
var sasPolicy = new SharedAccessBlobPolicy
{
SharedAccessExpiryTime = expirationDateTime,
Permissions = SharedAccessBlobPermissions.Create
};
return MediaContainer.Uri + blob.GetSharedAccessSignature(sasPolicy);
}
}
可以在这里找到博客帖子:您可以添加更多详细信息,如屏幕截图或其他信息来帮助您吗?