Windows Phone 8中的摄像头捕获任务

时间:2013-08-08 05:48:43

标签: windows-phone-8 isolatedstorage cameracapturetask

我正在开发Windows手机应用程序,我需要将摄像头中的捕获图像存储在隔离存储中,而不将其保存在相机胶卷中。我能够将捕获的图像存储在隔离的存储器中,但是捕获的图像的副本也存储在相机胶卷中。有什么方法可以将图像保存在隔离存储器中而不是相机存储器中。

由于

2 个答案:

答案 0 :(得分:2)

上面接受的答案对于Windows Phone 8 Silverlight 8.1

是不正确的

我使用Completed事件来自定义拍摄和接受照片后我想要执行的代码。

    public MainPage()
    {

        InitializeComponent();

        cameraTask = new CameraCaptureTask();
        cameraTask.Completed += new EventHandler<PhotoResult>(cameraTask_Completed);
        cameraTask.Show();

    }

    void cameraTask_Completed(object sender, PhotoResult e)
    {
        if (e.TaskResult != TaskResult.OK) 
            return;
            // Save picture as JPEG to isolated storage.
            using (IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream targetStream = isStore.OpenFile(fileName, FileMode.Create, FileAccess.Write))
                {
                    // Initialize the buffer for 4KB disk pages.
                    byte[] readBuffer = new byte[4096];
                    int bytesRead = -1;

                    // Copy the image to isolated storage. 
                    while ((bytesRead = e.ImageStream.Read(readBuffer, 0, readBuffer.Length)) > 0)
                    {
                        targetStream.Write(readBuffer, 0, bytesRead);
                    }
                }
            }

    }

资源 http://msdn.microsoft.com/library/windowsphone/develop/microsoft.phone.tasks.cameracapturetask http://code.msdn.microsoft.com/wpapps/CSWP8ImageFromIsolatedStora-8dcf8411

答案 1 :(得分:1)

如果要保存到仅隔离的存储空间,则无法使用CameraCaptureTask。在WP8中,无论您做什么,它都会透明地将图像副本保存到相机胶卷。

那说,有一个解决方案。您需要使用相机API来基本创建和使用您自己的CameraCaptureTask。我不打算深入研究,但这应该让你开始。

您需要做的第一件事就是按照this tutorial创建视图和基本应用程序。他们使用cam_CaptureImageAvailable方法将图像存储到相机胶卷。您需要修改它以将其存储在隔离存储中,如下所示:

using (e.ImageStream)
{
   using(IsolatedStorageFile storageFile = IsolatedStorageFile.GetuserStoreForApplication())
   {
      if( !sotrageFile.DirectoryExists(<imageDirectory>)
      {
         storageFile.CreateDirectory(<imageDirectory>);
      }

      using( IsolatedStorageFileStream targetStream = storageFile.OpenFile( <filename+path>, FileMode.Create, FileAccess.Write))
      {
         byte[] readBuffer = new byte[4096];
         int bytesRead;
         while( (bytesRead = e.ImageStream.Read( readBuffer, 0, readBuffer.Length)) > 0)
         {
            targetStream.Write(readBuffer, 0, bytesRead);
         }
      }
   }
}

从这一点来说,您有一个功能相机应用程序,仅存储到隔离存储。你可能想用色彩效果或其他东西加以调味,但这不是必需的。