我尝试在CameraCaptureTask
回调中保存图片时遇到异常。这是为什么 ?我正在通过WPConnect.exe
进行调试,我必须具备ID_CAP_MEDIALIB
的功能。
void photoChooserTask_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
string fileName = adViewModel.Id + DateTime.Now.Ticks + ".jpg";
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (myIsolatedStorage.FileExists(fileName))
{
myIsolatedStorage.DeleteFile(fileName);
}
IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(fileName);
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(e.ChosenPhoto);
WriteableBitmap wb = new WriteableBitmap(bitmap);
wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);
fileStream.Close();
fileStream = myIsolatedStorage.OpenFile(fileName, FileMode.Open, FileAccess.Read);
MediaLibrary library = new MediaLibrary();
// this line throw the exception
Picture pic = library.SavePictureToCameraRoll(fileName, fileStream);
}
}
}