2
我製作了一個使用實時拼貼的應用程序。我得到它與backgroundtask工作,它顯示了正確的消息,但圖像是全黑的...我的瓷磚創建和加載有什麼問題?
這裏是我的代碼,我將圖像保存到/Shared/ShellContent/
:
public MainPage()
{
InitializeComponent();
CurrentPlaceList = new ObservableCollection<CurrentPlaceListItemModel>();
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
var bmp = new WriteableBitmap(173, 173);
var weatherImage = new BitmapImage(new Uri("/Images/WeatherIcons/01d.png", UriKind.Relative));
var img = new Image { Source = weatherImage };
weatherImage.CreateOptions = BitmapCreateOptions.None;
var tt = new TranslateTransform();
tt.X = 0;
tt.Y = 0;
bmp.Render(img, tt);
bmp.Invalidate();
var filename = "/Shared/ShellContent/01d.jpg";
using (var st = new IsolatedStorageFileStream(filename, FileMode.OpenOrCreate, FileAccess.Write, store))
{
bmp.SaveJpeg(st, 173, 173, 0, 100);
}
}
StartAgent();
}
那裏是我的代碼在我的ScheduledTask應該更新的文字和圖像,這些圖像是全黑:(
protected override void OnInvoke(ScheduledTask task)
{
//TODO: Add code to perform your task in background
UpdateAppTile("-99");
NotifyComplete();
}
private void UpdateAppTile(string message)
{
ShellTile appTile = ShellTile.ActiveTiles.FirstOrDefault();
if (appTile != null)
{
StandardTileData tileData = new StandardTileData
{
Title = message,
BackgroundImage = new System.Uri("isostore:/Shared/ShellContent/01d.jpg", System.UriKind.Absolute)
};
appTile.Update(tileData);
}
}
這是從幾個教程採取,任何人都可以把手指上有什麼不好?
也許你需要等待'ImageLoaded'事件再渲染到'bmp'或者只是將圖像複製到'/ Shared/ShellContent /'目錄而不創建額外的'Image'對象。另外,您可以查看「獨立存儲」以查看此處保存的內容 – Ku6opr 2012-03-21 09:32:26