このコードは ScheduledTaskAgent.cs にあり、もちろんバックグラウンドで実行されます。
私はいつもステートメントでこの例外を受け取ります: stream.Seek(0, SeekOrigin.Begin); 画像は私のプロジェクトファイルのルートにあります。「コピーしない」と「常にコピーする」で試しましたが、それでも同じエラーが発生します。
Deployment.Current.Dispatcher.BeginInvoke(()=>
{
BitmapImage img = new BitmapImage(new Uri(@"\DefaultImage.jpg", UriKind.Relative));
img.CreateOptions = BitmapCreateOptions.None;
img.ImageOpened += (s, e) =>
{
WriteableBitmap wbitmap = new WriteableBitmap((BitmapImage)s);
TextBlock textBlock = new TextBlock();
textBlock.Text = "Sample Text";
textBlock.TextWrapping = TextWrapping.Wrap;
wbitmap.Render(textBlock, new TranslateTransform() { X = 25, Y = 10 }); ;
wbitmap.Invalidate();
using (MemoryStream stream = new MemoryStream())
{
wbitmap.SaveJpeg(stream, wbitmap.PixelWidth, wbitmap.PixelHeight, 0, 100);
stream.Seek(0, SeekOrigin.Begin);
SaveToIsolatedStorage(stream);
stream.Close();
}
};
});