2017-02-22 6 views
2

Je tente de capturer une photo dans mon application hololens. Il semble fonctionner mais enregistrer l'image dans un endroit obscur que je ne peux ni accéder ni voir. Je veux l'enregistrer dans ma bibliothèque d'images Described here I think. Ou où devrais-je enregistrer l'image afin que je puisse le voir dans mes photos sur les hololens.Enregistrement d'une image dans un dossier Photos Hololens App

filePath = C:/données/Utilisateurs/JanikJoe/AppData/Local/Forfaits/HoloToolkit-Unity_pzq3xp76mxafg/LocalState \ CapturedImage10.02831_n.jpg

filePath2 = C:/données/Utilisateurs/DefaultAccount/AppData/Local /DevelopmentFiles/HoloToolkit-UnityVS.Debug_x86.janik/Data\CapturedImage10.02831_n.jpg

using UnityEngine; 
using UnityEngine.VR.WSA.WebCam; 
using System.Linq; 

public class PhotoCaptureFVTC : MonoBehaviour { 

UnityEngine.VR.WSA.WebCam.PhotoCapture photoCaptureObject = null; 
// Use this for initialization 
void Start() 
{ 
    Debug.Log("snap pic taken"); 
    PhotoCapture.CreateAsync(false, OnPhotoCaptureCreated); 
} 

public void OnPhotoCaptureCreated(PhotoCapture captureObject) 
{ 
    photoCaptureObject = captureObject; 

    //Resolution cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First(); 
    Resolution cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First(); 

    CameraParameters c = new CameraParameters(); 
    c.hologramOpacity = 0.0f; 
    c.cameraResolutionWidth = cameraResolution.width; 
    c.cameraResolutionHeight = cameraResolution.height; 
    c.pixelFormat = CapturePixelFormat.BGRA32; 

    captureObject.StartPhotoModeAsync(c, false, OnPhotoModeStarted); 
} 
void OnStoppedPhotoMode(PhotoCapture.PhotoCaptureResult result) 
{ 
    photoCaptureObject.Dispose(); 
    photoCaptureObject = null; 
} 

private void OnPhotoModeStarted(PhotoCapture.PhotoCaptureResult result) 
{ 
    if (result.success) 
    { 
     string filename = string.Format(@"CapturedImage{0}_n.jpg", Time.time); 
     string filePath = System.IO.Path.Combine(Application.persistentDataPath, filename); 
     string filePath2 = System.IO.Path.Combine(Application.dataPath, filename); 

     photoCaptureObject.TakePhotoAsync(filePath, PhotoCaptureFileOutputFormat.JPG, OnCapturedPhotoToDisk); 
     Debug.LogError("Saved That Image Somewhere" +"FileName: ="+ filename + " FilePath: = " + filePath + " FilePath2: = " + filePath2); 
    } 
    else 
    { 
     Debug.LogError("Unable to start photo mode!"); 
    } 
} 
void OnCapturedPhotoToDisk(PhotoCapture.PhotoCaptureResult result) 
{ 
    if (result.success) 
    { 
     Debug.Log("Saved Photo to disk!"); 
     photoCaptureObject.StopPhotoModeAsync(OnStoppedPhotoMode); 
    } 
    else 
    { 
     Debug.Log("Failed to save Photo to disk"); 
    } 
} 


} 

Répondre

3

il semble qu'il ne soit pas possible d'enregistrer directement dans le dossier de rouleau de caméra et il n'y a pas de bibliothèque d'image sur la HoloLens.

Il y a la même question ici: https://forums.hololens.com/discussion/1458/capturing-photo-in-unity-and-saving-to-disk

J'ai essayé la solution de contournement et il fonctionne très bien. Il suffit de déplacer l'image enregistrée dans le dossier de rouleau de la caméra.

#if !UNITY_EDITOR && UNITY_WINRT_10_0 
     var cameraRollFolder = Windows.Storage.KnownFolders.CameraRoll.Path;    
     File.Move(_filePath, Path.Combine(cameraRollFolder, _filename)); 
#endif