此代码在 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();
}
};
});