Windows phone 7 类型为';System.Runtime.InteropServices.COMException';发生在Microsoft.Phone.ni.dll中,但未在用户代码中处理
这段代码在ScheduledTaskAgent.cs中,当然在后台运行 我总是在语句stream.Seek(0,SeekOrigin.Begin)处得到这个异常; 该图像位于我的项目文件根目录下。我尝试了“不复制”和“始终复制”。但仍然出现相同的错误Windows phone 7 类型为';System.Runtime.InteropServices.COMException';发生在Microsoft.Phone.ni.dll中,但未在用户代码中处理,windows-phone-7,windows-phone-8,windows-phone-7.1,Windows Phone 7,Windows Phone 8,Windows Phone 7.1,这段代码在ScheduledTaskAgent.cs中,当然在后台运行 我总是在语句stream.Seek(0,SeekOrigin.Begin)处得到这个异常; 该图像位于我的项目文件根目录下。我尝试了“不复制”和“始终复制”。但仍然出现相同的错误 Deployment.Current.Dispatcher.BeginInvoke(()=> { BitmapImage img = new BitmapImage(new Uri
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();
}
};
});
我认为SaveJpeg方法会关闭流,之后无法在其中查找。试试这个:
使用(IsolatedStorageFileStream=IsolatedStorageFile.GetUserStoreForApplication().CreateFile(文件名))
{
SaveJpeg(stream,wbitmap.PixelWidth,wbitmap.PixelHeight,0100);
}