获取存储在isolatedstorage中的图像的URI

时间:2013-12-14 16:37:19

标签: windows-phone-8 live tile

我使用此代码在isolatedstorage中保存了一个名为'logo.jpg'的文件...

private void step2_Click(object sender, RoutedEventArgs e)
        {
            // Create a filename for JPEG file in isolated storage.
            String tempJPEG = "logo.jpg";

            // Create virtual store and file stream. Check for duplicate tempJPEG files.
            using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (myIsolatedStorage.FileExists(tempJPEG))
                {
                    myIsolatedStorage.DeleteFile(tempJPEG);
                }

                IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(tempJPEG);

                try
                {
                    WriteableBitmap wb = new WriteableBitmap(img);

                    // Encode WriteableBitmap object to a JPEG stream.
                    Extensions.SaveJpeg(wb, fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);
                }
                catch { }
                //wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);
                fileStream.Close();
            }
            NavigationService.Navigate(new Uri("/Stage2.xaml?num="+Contact_number.Text+"&name="+contact_name.Text, UriKind.Relative));
        }

使用此功能创建磁贴..

private StandardTileData GetSecondaryTileData()
    {
        string filePath = System.IO.Path.Combine(@"/Shared/ShellContent", "logo.jpg");

        StandardTileData tileData = new StandardTileData
        {
            Title = name,
            BackgroundImage = new Uri(@"isostore:" + filePath, UriKind.Absolute),
            Count = 0,
            BackTitle = "app",
            BackBackgroundImage = new Uri("", UriKind.Absolute),
            BackContent = "content"
        };

但它正在抛出异常 “System.ni.dll中发生了'System.UriFormatException'类型的异常,但未在用户代码中处理

其他信息:无效的URI:URI为空。“

2 个答案:

答案 0 :(得分:1)

问题是图像不在共享/ shellcontent /以及

BackBackgroundImage = new Uri("", UriKind.Absolute),

这是不正确的。如果瓷砖必须保持空白,它应该是相对的...花了这么多时间。吞吐

答案 1 :(得分:0)

使用此

MediaLibraryExtension.GetPath(p);

这里p是Class Picture的对象(它将返回路径的图片)