我正在尝试将图像保存,即存在于我的项目中的隔离存储中。我尝试使用以下代码,但它抛出System.NullReferenceException。
IsolatedStorageFileStream fileStream1 = myIsolatedStorage.CreateFile("shared/shellcontent/image.jpg");
Uri uri = new Uri(@"/myapp;/component/contact.bmp", UriKind.Relative);
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.UriSource = uri;
WriteableBitmap wb = new WriteableBitmap(bitmapImage); //throwing exception
Extensions.SaveJpeg(wb, fileStream1, wb.PixelWidth, wb.PixelHeight, 0, 85);
我也尝试了jpg图像。复制到输出目录设置为从不复制。还尝试将构建操作设置为内容
............. 刚试过这段代码,现在没有显示异常,但仍然在设置为平铺背景时。它的空白
Uri uri = new Uri("contact.jpg", UriKind.Relative);
StreamResourceInfo sri = null;
sri = Application.GetResourceStream(uri);
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(sri.Stream);
WriteableBitmap wb = new WriteableBitmap(bitmapImage);
Extensions.SaveJpeg(wb, fileStream1, wb.PixelWidth, wb.PixelHeight, 0, 85);
更新: 问题已解决。文件流未关闭。傻了我