Reputation: 106
Im experiencing problems with the background image at a secondary live tile in my windows phone app, it does not stretch and fit the tile properly (it is a .png image)
I get the data and then create my tile data:
var tileData = new StandardTileData
{
Title = titleString,
BackContent = contentString,
BackTitle = backTitleString,
BackgroundImage = new Uri(httpUrlString)
};
is there any way to change the stretch or "retemplate" the tile?
Also i found a solution here with a writeablebitmap, but I cannot understand how to give this bitmap as a source, since the backgroundimage property only accepts a Uri
Upvotes: 0
Views: 634
Reputation: 106
the problem was the image was not fully loaded, and therefore not properly rendered. I used the ImageOpened event and then saved it as Olivier suggested
Upvotes: 1
Reputation: 15268
You need to resize the image to give it the good aspect ratio (see the answer here)
Then you'll have to save the resulting WriteableBitmap in the Isolated Storage, like this:
// save image to isolated storage
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
{
// use of "/Shared/ShellContent/" folder is mandatory!
using (IsolatedStorageFileStream imageStream = new IsolatedStorageFileStream("/Shared/ShellContent/MyImage.jpg", System.IO.FileMode.Create, isf))
{
wbmp.SaveJpeg(imageStream, wbmp.PixelWidth, wbmp.PixelHeight, 0, 100);
}
}
You will then be able to create the tile like this:
StandardTileData NewTileData = new StandardTileData
{
Title = "Title",
// reference saved image via isostore URI
BackgroundImage = new Uri("isostore:/Shared/ShellContent/MyImage.jpg", UriKind.Absolute),
};
Upvotes: 2