Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.
Options

Saving image to the Photos folder in Hololens app

I'm attempting to capture a photo inside my hololens app. It seems to be working but saving the image to an obscure place that I cant access or view. I want to save the image so I can see it in my photos on the hololens.

filePath = C:/Data/Users/JanikJoe/AppData/Local/Packages/HoloToolkit-Unity_pzq3xp76mxafg/LocalState\CapturedImage10.02831_n.jpg

filePath2 = C:/Data/Users/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");
    }
}
}

Best Answer

Answers

  • Options

    @james_ashley said:
    Hi @JD_Holo_Dev,

    To get the path to my pictures, you can try:

    string filePath = System.IO.Path.Combine(Windows.Storage.KnownFolders.PicturesLibrary.Path, filename);

    Be sure to add My Pictures to the capabilities for your app.

    @james_ashley said:
    Hi @JD_Holo_Dev,

    To get the path to my pictures, you can try:

    string filePath = System.IO.Path.Combine(Windows.Storage.KnownFolders.PicturesLibrary.Path, filename);

    Be sure to add My Pictures to the capabilities for your app.

    Hello, im trying to use your filePath but i found and error on Windows.Storage
    "Windows doesn't exist in the current context"
    any idea? about this error?

  • Options

    Hi Eslas,

    did you got output for this.i am facing the same problem.

    need your help.

  • Options

    Hi Eslas,

    did you got output for this.
    need your help

Sign In or Register to comment.