Reputation: 81
I have an application that saves images to the pictures library. That works fine as I added permissions to use the pictures library in the app manifest.
I am now trying to create a live tile that will show these images which were saved to the picture library but i can't seem to get that working.
I saw that it is possible to create a URI to the app local folder or to the app installed folder, but I didn't find an example of using an absolute path or a relative path to the pictures library.
Any help would be appreciated
Thanks
XmlDocument wideTileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWide310x150Image);
XmlNodeList wideTileImageAttributes = wideTileXml.GetElementsByTagName("image");
((XmlElement)wideTileImageAttributes[0]).SetAttribute("src", fileAbsPath);
((XmlElement)wideTileImageAttributes[0]).SetAttribute("alt", "");
// Create a new tile notification.
updater.Update(new TileNotification(wideTileXml));
Upvotes: 0
Views: 508
Reputation: 7024
As described on http://msdn.microsoft.com/en-us/library/windows/apps/hh465439.aspx, tile image references can use ms-appx:///, ms-appdata:///, or http[s]:// URIs. That is.
As you suggest, then, you need to copy the image from the pictures library to your local app data. Use the StorageFile.copyAsync method for this. Also be aware, however, that tile images are limited to 200KB, and it's likely that most of the images in the Pictures library are far larger than that. This means that you'll need to change the size in the process. Scenario 2 of the Simple imaging sample has code for this.
Alternately, you can first call StorageFile.getScaledImageAsThumbnailAsync for the image in Pictures, requesting a thumbnail size appropriate for the tile template you're using. The thumbnail itself is returned as a StorageItemThumbnail which is a random access stream, so you'll need to copy those bytes into the file in local app data. You should be able to use the Simple imaging sample code again, picking it up where you have the input stream and going from there.
Another piece of code that I'll mention is written in JavaScript, but might be useful: it's scenario 11 of the JavaScript App tiles and badges sample, which is an image editor for tiles. You might be able to use some of the code here, though you'd have to translate to C#.
Upvotes: 1