2017-02-22 184 views
2

我試圖捕捉我的hololens應用程序內的照片。它似乎在工作,但將圖像保存到我無法訪問或查看的模糊地點。我想將它保存到我的圖片庫Described here I think。或者我應該在哪裏保存圖像,以便我可以在我的hololens照片中看到它。將圖像保存到照片文件夾在hololens應用程序

文件路徑= C:/數據/用戶/ JanikJoe /應用程序數據/本地/封裝/ HoloToolkit-Unity_pzq3xp76mxafg/LocalState \ CapturedImage10.02831_n.jpg

FILEPATH2 = C:/數據/用戶/ DefaultAccount /應用程序數據/本地/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"); 
    } 
} 


} 

回答

3

這似乎是,這是無法直接保存在相機膠捲文件夾並沒有圖片庫上HoloLens。

有同樣的問題在這裏:https://forums.hololens.com/discussion/1458/capturing-photo-in-unity-and-saving-to-disk

我嘗試瞭解決方法,它工作正常。只需將保存的圖像移動到相機膠捲文件夾。

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