문제

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.

Thanks

도움이 되었습니까?

해결책 2

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.

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.

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.

다른 팁

The accepted answer above is not correct for Windows Phone 8 Silverlight 8.1

I used the Completed event to customize the code I want to be executed after the photo is taken and accepted.

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

    }

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top