Windows Phone 8 中的相机捕获任务 [英] Camera Capture Task in windows phone 8

查看:11
本文介绍了Windows Phone 8 中的相机捕获任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发 Windows Phone 应用程序,在该应用程序中,我需要将来自相机的捕获图像存储在独立存储中,而不将其保存在相机胶卷中.我能够将捕获的图像存储在独立存储中,但捕获的图像的副本也存储在相机胶卷中.有什么办法可以将图像保存在隔离存储中而不是相机胶卷中.

I am working on windows phone application in which i need to store a captured image from the camera in isolated storage without saving it in the camera roll. I am able to store the captured image in the isolated storage but a copy of the captured image in also stored in the camera roll. Is there any way i can keep the image within the isolated storage rather than the camera roll.

谢谢

推荐答案

如果您只想保存到单独的存储,则不能使用 CameraCaptureTask.在 WP8 中,无论您做什么,它都会透明地将图像副本保存到相机胶卷中.

If you want to save to ONLY isolated storage, you cannot use the CameraCaptureTask. In WP8, it will transparently save a copy of the image to the camera roll, regardless of what you do.

也就是说,有一个解决方案.您需要使用相机 API 来基本上创建和使用您自己的 CameraCaptureTask.我不打算深入探讨,但这应该能让您入门.

That said, there is a solution. You'll need to use the camera APIs to basically create and use your own CameraCaptureTask. I'm not going to go into huge depth, but this should get you started.

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

First thing you need to do is follow this tutorial to create the view and basic application. They use the cam_CaptureImageAvailable method to store the image to the camera roll. You'll want to modify that to store it in isolated storage like so:

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);
         }
      }
   }
}

从现在开始,您就有了一个功能强大的相机应用程序,它只能存储到隔离的存储中.你可能想用颜色效果或其他东西来增加它的趣味,但这不是必需的.

From this point, you have a functional camera application that stores only to isolated storage. You may want to spice it up with color effects or something, but it's not necessary.

这篇关于Windows Phone 8 中的相机捕获任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆