此代码位于ScheduledTaskAgent.cs中,并且ofcourse在后台运行。
我总是在语句中得到这个异常:stream.Seek(0,SeekOrigin.Begin); 图像位于root下的项目文件中。我尝试使用“不复制”和“始终复制”。但仍然出现相同的错误。
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();
}
};
});
答案 0 :(得分:0)
我认为SaveJpeg方法会关闭流,之后您无法进行搜索。试试这个:
using (IsolatedStorageFileStream stream = IsolatedStorageFile.GetUserStoreForApplication().CreateFile(fileName))
{
wbitmap.SaveJpeg(stream, wbitmap.PixelWidth, wbitmap.PixelHeight, 0, 100);
}