使用MediaLibrary的SavePictureToCameraRoll时出现InvalidOperationException

时间:2011-12-12 08:55:20

标签: windows-phone-7

我尝试在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);
        }
    }
}

1 个答案:

答案 0 :(得分:0)

根据此MSDN entry如果手机连接到计算机,SavePicture将抛出异常。我想SavePictureToCameraRoll会是一样的。