locked
Can't get image from StorageFile to show in Live Tile

    Question

  • I have a Windows Store app written in C# that works with photos.  I want to show the last photo the user selected in the app in the medium size live tile (150 x 150).  I am using the code below to do it.  When I run the app I don't get any errors, but I don't see the selected photo in the live tile either.  I know that I am doing at least some things right.  I say this because if the user hasn't selected a photo yet, then I show a test image and I do see that image in the tile.  But the test image comes from the app package using the ms-appx protocol, not from the app storage area.

    I found a few forum posts on the subject but they are all for Windows Phone.  I looked at the KnownFolders list for Windows Store app files, but nothing seemed to map to the SharedContent folder required for files meant for live tile use in Windows Phone.  What is wrong with my code?

    Note, the vvm.ActiveVideomark.GetThumbnail() call simply retrieves a bitmap as a WriteableBitmap object.  As you can see in the code, I am resizing the image to the size required by the Medium live tile (150 x 150).  ToJpegFileAsync()is an extension method that encodes a WriteableBitmap object to jpeg bytes and then writes those bytes to a file using the given file name.  Both of these calls are well-tested and are not the source of the problem as far as I know.

                TileUpdateManager.CreateTileUpdaterForApplication().Clear();
                TileUpdateManager.CreateTileUpdaterForApplication().EnableNotificationQueue(true);
    
                var tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150Image);
    
                var tileImage = tileXml.GetElementsByTagName("image")[0] as XmlElement;
    
                // Got a current photo?
                if (vvm.ActiveVideomark == null)
                    // No, just show the regular logo image.
                    tileImage.SetAttribute("src", "ms-appx:///Assets/Logo.scale-100.png");
                else
                {
                    // Resize it to the correct size.
                    WriteableBitmap wbm = await vvm.ActiveVideomark.GetThumbnail();
                    WriteableBitmap wbm2 = wbm.Resize(150, 150, WriteableBitmapExtensions.Interpolation.Bilinear);
    
                    // Write it to a file so we can pass it to the Live Tile.
                    string jpegFilename = "LiveTile1.jpg";
                    StorageFile jpegFile = await wbm2.ToJpegFileAsync(jpegFilename);
    
                    // Yes, show the selected image.
                    tileImage.SetAttribute("src", jpegFile.Path);
                }


    -- roschler


    • Edited by roschler Thursday, August 28, 2014 3:45 PM
    Thursday, August 28, 2014 3:45 PM

Answers

All replies

  • Where is ToJpegFileAsync saving the file?

    Images can be used from the app's package, the app's local storage, or from the web. If you're saving it elsewhere then it is not expected to show up. You can reference local data with the ms-appdata:///local/<name> URI.

    --Rob

    Thursday, August 28, 2014 3:51 PM
    Owner
  • Hi Rob,

    Is there any convenient way to convert the path from the Path property of a StorageFile object to the correct ms-appdata URI that will allow the Live Tile to access it properly?  In other words, how to get from:

    C:\Users\\Robert\Pictures\LiveTile1.jpg

    To the correct ms-appdata URI:

    ms-appdata:///local/<name>



    -- roschler


    • Edited by roschler Thursday, August 28, 2014 4:17 PM
    Thursday, August 28, 2014 4:08 PM
  • C:\Users\Robert\Pictures sounds like your Pictures library, not your local app data.

    The tile cannot come from the libraries, but you can copy the picture to your local data and then point the tile at it there.

    --Rob

    Thursday, August 28, 2014 5:50 PM
    Owner