如何检索在 Windows Azure 中存储为 Base64String 的图像?我知道如何在 Windows Azure 中将图像保存为 Base64String,但我不知道如何检索它。
将数据作为 Base64String 保存到 Windows Azure 存储:
private MemoryStream str;
str = new MemoryStream();
WriteableBitmap wb;
wb = new WriteableBitmap(bmp);
wb.SaveJpeg(str, bmp.PixelWidth, bmp.PixelHeight, 0, 100);
Item item = new Item { ImageString = System.Convert.ToBase64String(str.ToArray()) };
App.MobileService.GetTable<Item>().InsertAsync(item);
类(class):
public class Item
{
public int Id { get; set; }
public string ImageString { get; set; }
}
最佳答案
您可以通过id(调用InsertAsync
后返回)查询图像:
private void RetrieveImage(int id) {
var item = await App.MobileService.GetTable<Item>().LookupAsync(id);
byte[] imageBytes = Convert.FromBase64String(item.ImageString);
}
或者检索所有图像:
private void RetrieveAllImages() {
var images = await App.MobileService
.GetTable<Item>()
.Select(i => Convert.FromBase64String(i.ImageString))
.ToListAsync();
}
或者使用任意属性(而不是 id)进行查询 - 假设 Item 类有一个名为“Name”的属性:
var items = await App.MobileService.GetTable<Item>()
.Where(it => it.Name == "MyImage")
.ToEnumerableAsync();
var item = item.FirstOrDefault();
关于c# - 从 Windows Azure 存储检索图像 (Base64String),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17403538/