0

我编写以下代码来保存一些来自互联网的图像:

    public static async Task SaveImage(string name, string uri)
    {
        var localfolder = ApplicationData.Current.LocalFolder;
        var client = new HttpClient();

        var imageStream = await client.GetStreamAsync(uri); //Secuencia de bytes
        var storageFile = await localfolder.CreateFileAsync(name, CreationCollisionOption.ReplaceExisting);

        using (Stream outputStream = await storageFile.OpenStreamForWriteAsync())
        {
            await imageStream.CopyToAsync(outputStream);
        }
    }

我的问题是当我尝试将本地存储中的这些图像存储设置为 CycleTile 时,因为此类需要 Uri,而我不知道如何在此处提供 uri。这就是我所拥有的:

        CycleTileData cycleicon = new CycleTileData();
        cycleicon.Title = "Fotopantalla";
        cycleicon.Count = 0;
        cycleicon.SmallBackgroundImage = new Uri("/Assets/Tiles/FlipCycleTileSmall.png", UriKind.RelativeOrAbsolute);
        List<Uri> images = new List<Uri>();

        for (int i = 0; i < 9; i++)
        {
            /// tries...
            string path1 = "ms-appdata:///local/image" + i + ".jpg";
            string path2 = "isostore:/Shared/ShellContent/image" + i + ".jpg";
            string path3 = "ms-appdata:///Local/Shared/ShellContent/image" + i + ".jpg";
            ///

            Uri uri = new Uri(path2, UriKind.RelativeOrAbsolute);
            images.Add(uri);
        }

        cycleicon.CycleImages = images;

我错了什么或我错过了什么?

4

1 回答 1

0

对于任何与 ShellTileData 相关的数据结构,如果图像不在(只读)InstalledLocation 文件夹中,则必须使用 path2: "isostore:/Shared/ShellContent/*"。

有关更多详细信息,请参阅:http: //blogs.msdn.com/b/andy_wigley/archive/2013/04/10/live-apps-creating-custom-tile-and-lock-screen-images.aspx

我的代码中有类似的东西:

var store = IsolatedStorageFile.GetUserStoreForApplication();
if (!store.DirectoryExists("Shared/ShellContent"))
{
    store.CreateDirectory("Shared/ShellContent");
}
StorageFolder shellContent = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFolderAsync("Shared", CreationCollisionOption.OpenIfExists);
shellContent = await shellContent.CreateFolderAsync("ShellContent", CreationCollisionOption.OpenIfExists);

Stream imgin = picture.GetImage(); 
//Picture read stream from Media Library or other input stream

StorageFile new_img = await shellContent.CreateFileAsync(newPictureName);
Stream imgout = await new_img.OpenStreamForWriteAsync();

imgin.CopyTo(imgout);

imgout.Close(); // <- necessary in your code or not?
imgin.Close(); // <-

我不确定,一开始你是否真的需要 Isostore,但如果我在缩短代码时没有犯一些愚蠢的错误,它就可以工作。;-)

还可以查看 Microsoft 开发中心的“StandardTileData.BackgroundImage 属性”、“Windows Phone 数据”和“如何使用 Windows Phone 的独立存储资源管理器工具”。(最后一个是关于如何查看设备上保存的图像文件。)

于 2013-07-08T03:07:18.340 回答