Windows Phone 8.1 用にアプリを更新していて、透明なライブ タイルを作成したいと考えています。PNG画像を作成するためにToolStack PNGライブラリを使用していますが、最初の外観では問題なく動作します! バックグラウンドタスクで以下のコードを使用しています
private void CreateWideTile()
{
int width = 691;
int height = 336;
string imagename = "WideBackground";
WriteableBitmap b = new WriteableBitmap(width, height);
var canvas = new Grid();
canvas.Width = b.PixelWidth;
canvas.Height = b.PixelHeight;
var textBlock = new TextBlock();
textBlock.Text = "example text...";
textBlock.Margin = new Thickness(10, 55, 0, 0);
textBlock.Width = 140;
textBlock.Foreground = new SolidColorBrush(Colors.White);
textBlock.FontSize = 30;
canvas.Children.Add(textBlock);
b.Render(canvas, null);
b.Invalidate();
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
if (store.FileExists("/Shared/ShellContent/" + imagename + ".png"))
store.DeleteFile("/Shared/ShellContent/" + imagename + ".png");
var stream = store.OpenFile("/Shared/ShellContent/" + imagename + ".png", FileMode.OpenOrCreate);
b.WritePNG(stream);
stream.Close();
}
}
private void CreateMediumTile()
{
int width = 336;
int height = 336;
string imagename = "MediumBackground";
WriteableBitmap b = new WriteableBitmap(width, height);
var canvas = new Grid();
canvas.Width = b.PixelWidth;
canvas.Height = b.PixelHeight;
var textBlock = new TextBlock();
textBlock.Text = "example text...";
textBlock.Margin = new Thickness(10, 55, 0, 0);
textBlock.Width = 140;
textBlock.Foreground = new SolidColorBrush(Colors.White);
textBlock.FontSize = 30;
canvas.Children.Add(textBlock);
b.Render(canvas, null);
b.Invalidate();
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
if (store.FileExists("/Shared/ShellContent/" + imagename + ".png"))
store.DeleteFile("/Shared/ShellContent/" + imagename + ".png");
var stream = store.OpenFile("/Shared/ShellContent/" + imagename + ".png", FileMode.OpenOrCreate);
b.WritePNG(stream);
stream.Close();
}
}
private void CreateSmallTile()
{
int width = 159;
int height = 159;
string imagename = "SmallBackground";
WriteableBitmap b = new WriteableBitmap(width, height);
var canvas = new Grid();
canvas.Width = b.PixelWidth;
canvas.Height = b.PixelHeight;
var textBlock = new TextBlock();
textBlock.Text = "example text...";
textBlock.Margin = new Thickness(10, 55, 0, 0);
textBlock.Width = 140;
textBlock.Foreground = new SolidColorBrush(Colors.White);
textBlock.FontSize = 30;
canvas.Children.Add(textBlock);
b.Render(canvas, null);
b.Invalidate();
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
if (store.FileExists("/Shared/ShellContent/" + imagename + ".png"))
store.DeleteFile("/Shared/ShellContent/" + imagename + ".png");
var stream = store.OpenFile("/Shared/ShellContent/" + imagename + ".png", FileMode.OpenOrCreate);
b.WritePNG(stream);
stream.Close();
}
}
前述したように、このコードは正常に動作しますが、5 回実行するとバックグラウンド タスクが終了し、実行されなくなります...本当に混乱しています。私はすべてのインターネットを検索しましたが、問題はメモリリークが原因だと思います。しかし、この紛らわしい問題を解決する方法がわかりません。GC.Collect(); も使用しました。しかし、それはまったく役に立ちませんでした。どうかアドバイスをお願いします