Windows phone 8 windows phone 8中的摄像头捕获任务

Windows phone 8 windows phone 8中的摄像头捕获任务,windows-phone-8,isolatedstorage,cameracapturetask,Windows Phone 8,Isolatedstorage,Cameracapturetask,我正在使用windows phone应用程序,在该应用程序中,我需要将相机拍摄的图像存储在单独的存储器中,而不将其保存在相机卷中。我可以将捕获的图像存储在单独的存储器中,但也可以将捕获图像的副本存储在相机卷中。我有没有办法将图像保存在单独的存储器中,而不是保存在胶卷中 谢谢如果只想保存到独立存储,则不能使用CameraCaptureTask。在WP8中,无论您做什么,它都会将图像的副本透明地保存到相机卷中 也就是说,有一个解决办法。您需要使用camera API来创建和使用自己的CameraCa

我正在使用windows phone应用程序,在该应用程序中,我需要将相机拍摄的图像存储在单独的存储器中,而不将其保存在相机卷中。我可以将捕获的图像存储在单独的存储器中,但也可以将捕获图像的副本存储在相机卷中。我有没有办法将图像保存在单独的存储器中,而不是保存在胶卷中


谢谢

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

也就是说,有一个解决办法。您需要使用camera API来创建和使用自己的
CameraCaptureTask
。我不打算深入研究,但这应该能让你开始

您需要做的第一件事是创建视图和基本应用程序。他们使用cam\u 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);
         }
      }
   }
}
使用(如ImageStream)
{
使用(IsolatedStorageFile storageFile=IsolatedStorageFile.GetuserStoreForApplication())
{
如果(!sotrageFile.DirectoryExists()
{
storageFile.CreateDirectory();
}
使用(IsolatedStorageFileStream targetStream=storageFile.OpenFile(,FileMode.Create,FileAccess.Write))
{
字节[]读缓冲区=新字节[4096];
int字节读取;
而((bytesRead=e.ImageStream.Read(readBuffer,0,readBuffer.Length))>0)
{
写(读缓冲区,0,字节读);
}
}
}
}

从这一点上说,您就拥有了一个只存储到独立存储的功能性相机应用程序。您可能想用色彩效果或其他东西来增加它的趣味性,但这不是必需的。

如果您只想保存到独立存储,您不能使用
CameraCaptureTask
。在WP8中,它将透明地将图像的副本保存到不管你做什么,镜头都会滚动

也就是说,有一个解决方案。您需要使用camera API基本上创建和使用您自己的
CameraCaptureTask
。我不打算深入讨论,但这应该可以让您开始

您需要做的第一件事是创建视图和基本应用程序。它们使用
cam\u 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);
         }
      }
   }
}
使用(如ImageStream)
{
使用(IsolatedStorageFile storageFile=IsolatedStorageFile.GetuserStoreForApplication())
{
如果(!sotrageFile.DirectoryExists()
{
storageFile.CreateDirectory();
}
使用(IsolatedStorageFileStream targetStream=storageFile.OpenFile(,FileMode.Create,FileAccess.Write))
{
字节[]读缓冲区=新字节[4096];
int字节读取;
而((bytesRead=e.ImageStream.Read(readBuffer,0,readBuffer.Length))>0)
{
写(读缓冲区,0,字节读);
}
}
}
}

从这一点上说,您有一个功能强大的摄像头应用程序,它只存储到独立的存储。您可能想用色彩效果或其他东西来增加它的趣味性,但这不是必需的。

上述公认的答案对于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);
                    }
                }
            }

    }
public主页()
{
初始化组件();
cameraTask=新的CameraCaptureTask();
cameraTask.Completed+=新事件处理程序(cameraTask_Completed);
cameraTask.Show();
}
无效cameraTask_已完成(对象发送方,照片结果e)
{
if(e.TaskResult!=TaskResult.OK)
返回;
//将图片另存为JPEG到独立存储。
使用(IsolatedStorageFile isStore=IsolatedStorageFile.GetUserStoreForApplication())
{
使用(IsolatedStorageFileStream targetStream=isStore.OpenFile(文件名,FileMode.Create,FileAccess.Write))
{
//初始化4KB磁盘页的缓冲区。
字节[]读缓冲区=新字节[4096];
int字节读取=-1;
//将映像复制到独立存储。
而((bytesRead=e.ImageStream.Read(readBuffer,0,readBuffer.Length))>0)
{
写(读缓冲区,0,字节读);
}
}
}
}
资源

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

    }
public主页()
{
初始化组件();
cameraTask=新的CameraCaptureTask();
cameraTask.Completed+=新事件处理程序(cameraTask_Completed);
cameraTask.Show();
}
无效cameraTask_已完成(对象发送方,照片结果e)
{
if(e.TaskResult!=TaskResult.OK)
返回;
//将图片另存为JPEG到独立存储。
使用(IsolatedStorageFile isStore=IsolatedStorageFile.GetUserStoreForApplication())
{
使用(IsolatedStorageFileStream targetStream=isStore.OpenFile(文件名,FileMode.Create,FileAccess.Write))
{
//初始化4KB磁盘页的缓冲区。
字节[]读缓冲区=新字节[4096];
int字节读取=-1;
//将映像复制到独立存储。
而((bytesRead=e.ImageStream.Read(readBuffer,0,readBuffer.Length))>0)
{
targetStream.Write(读缓冲区,0,b