C# 从独立存储中的映像设置次平铺背景映像

C# 从独立存储中的映像设置次平铺背景映像,c#,windows-phone-8,C#,Windows Phone 8,这是我从图像url获取流的方式: using (var httpClient = new HttpClient()) { response = await httpClient.GetStreamAsync(new Uri(IMAGEURL_HERE, UriKind.Absolute)); } SaveImage(response); 这就是我如何将其保存到IsolatedStorage的方法:

这是我从图像url获取流的方式:

        using (var httpClient = new HttpClient())
        {
            response = await httpClient.GetStreamAsync(new Uri(IMAGEURL_HERE, UriKind.Absolute));
        }

        SaveImage(response);
这就是我如何将其保存到IsolatedStorage的方法:

    private void SaveImage(Stream result)
    {
        using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
        {
            BitmapImage bitmap = new BitmapImage();
            bitmap.SetSource(result);
            var wb = new WriteableBitmap(bitmap);

            using (IsolatedStorageFileStream fileStream = file.CreateFile("FILENAME.jpg"))
            {
                int width = wb.PixelWidth;
                int height = wb.PixelHeight;
                if (wb.PixelWidth > 336)
                {
                    width = 336;
                }
                if (wb.PixelHeight > 336)
                {
                    height = 336;
                }
                Extensions.SaveJpeg(wb, fileStream, width, height, 0, 100);
            }
        }
    }
假设文件名为FILENAME.jpg,我想我可以将其设置为BackgroundImage,并设置为如下所示的辅助磁贴:

var tileData = new FlipTileData()
{
...
BackgroundImage = new Uri("isostore:/Shared/ShellContent/FILENAME.jpg", UriKind.Absolute),
...
这行不通。它不会引发异常,只有图像不会显示。我错过了什么?当然,如果我把图像Url作为Uri放在BackgroundImage中,它会工作,但这不是我想要的


编辑:我在这里看到过类似的问题,但它对我的代码没有帮助。

试试这个。也许是它的帮助

string imageFolder = @"\Shared\ShellContent"; 
string shareJPEG = "FILENAME.jpg";

private void SaveImage(Stream result)
{
    using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
    {
        if(!myIsolatedStorage.DirectoryExists(imageFolder))
        {
            myIsolatedStorage.CreateDirectory(imageFolder);
        }

        if (myIsolatedStorage.FileExists(shareJPEG))
        {
            myIsolatedStorage.DeleteFile(shareJPEG);
        }

        string filePath = System.IO.Path.Combine(imageFolder, shareJPEG);
        IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(filePath);
        BitmapImage bitmap = new BitmapImage();
        bitmap.SetSource(result);
        WriteableBitmap wb = new WriteableBitmap(bitmap);

        // Encode WriteableBitmap object to a JPEG stream. 
        int width = wb.PixelWidth;
        int height = wb.PixelHeight;
        if (wb.PixelWidth > 336)
        {
            width = 336;
        }
        if (wb.PixelHeight > 336)
        {
            height = 336;
        }
        Extensions.SaveJpeg(wb, fileStream, width, height, 0, 100);

        fileStream.Close();


    }
} 

private void CreateTile()
{
    var tileData = new FlipTileData()
    {
         ....
         string filePath = System.IO.Path.Combine(imageFolder, shareJPEG);                
         BackgroundImage = new Uri(@"isostore:" + filePath, UriKind.Absolute);
         ....
    } 
}

tileData.BackgroundImage=…我已经编辑了代码。下面是FlipTileData的ctor,所以创建互动程序不是问题,它很好用,也适用于站点的图像URL,但不适用于IsoStorage。FlipTileData()抛出System.UriFormatException。在创建磁贴之前,我已经检查了FileExists的路径,文件就在那里。有什么想法吗?检查我的最新答案。现在它对我来说非常好用。uri中缺少