首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >windows phone 8中的相机捕获任务

windows phone 8中的相机捕获任务
EN

Stack Overflow用户
提问于 2013-08-08 05:48:42
回答 2查看 1.3K关注 0票数 0

我正在开发windows应用程序,在该应用程序中,我需要将相机捕获的图像存储在隔离存储中,而不需要将其保存在相机卷中。我能够将捕获的图像存储在隔离存储中,但捕获图像的副本也存储在相机卷中。我有没有办法把图像保存在独立的存储器里,而不是相机卷里。

谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-08-08 11:52:39

如果希望仅保存到独立存储,则不能使用CameraCaptureTask。在WP8中,不管您做什么,它都会透明地将图像的副本保存到相机卷中。

尽管如此,还是有解决办法的。您需要使用camera来创建和使用您自己的CameraCaptureTask。我不打算深入,但这应该会让你开始。

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

代码语言:javascript
复制
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);
         }
      }
   }
}

从现在开始,您有一个只存储到隔离存储的功能相机应用程序。你可能想用颜色效果或其他东西来调味它,但这是不必要的。

票数 1
EN

Stack Overflow用户

发布于 2014-06-12 07:02:26

以上接受的答案对于Windows 8 Silverlight 8.1是不正确的

我使用已完成的事件来自定义我想要在照片被拍摄和接受之后执行的代码。

代码语言:javascript
复制
    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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18118749

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档