我的应用程序与flickr交互,我想添加5张图片,我从flickr json获取我的自行车贴砖,怎么做?关于制作循环图块的大部分教程都是使用资产中的图像,而没有教授如何使用Web服务的图像。
答案 0 :(得分:0)
我使用Brian Farnhill的这个课程:
public class TileManager
{
public const string StoragePath = "Shared/ShellContent";
public static async Task SaveTileImage(Uri uri, string filename, string folder = StoragePath)
{
var client = new HttpClient();
var isf = IsolatedStorageFile.GetUserStoreForApplication();
if (!isf.DirectoryExists(StoragePath))
isf.CreateDirectory(StoragePath);
var file = (folder == null ? filename : String.Format("{0}/{1}", folder, filename));
if (isf.FileExists(file)) isf.DeleteFile(file);
using (var stream = isf.OpenFile(file, FileMode.Create, FileAccess.ReadWrite))
{
var bytes = await client.GetByteArrayAsync(uri);
var ms = new MemoryStream(bytes, false);
await ms.CopyToAsync(stream);
}
}
public static void UpdateCycleTile(Uri smallBackgroundImage, string folder, string[] filesToShow, ShellTile currentTile)
{
var cycleTile = new CycleTileData
{
Title = "Stitch",
SmallBackgroundImage = smallBackgroundImage,
CycleImages = filesToShow.Select(str => String.Format("isostore:/{0}/{1}", folder, str).ToUri()).ToArray()
};
currentTile.Update(cycleTile);
}
}
别忘了为HttpClient(nuget)添加特定的使用和包。