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

Taking a Picture on a tap event

I want to take a photo when the user air taps with the hololens.

How do I call the function public void OnPhotoCaptureCreated(PhotoCapture captureObject)
In PhotoCaptureFVTC class from the GestureManager class's tap event?

Is that the right function to call to start the photo taking process?

I'm working from this tutorial https://developer.microsoft.com/en-us/windows/holographic/locatable_camera_in_unity

I need to start he picture process in the tap event below.
private void OnTap() { if (FocusedObject != null) { FocusedObject.SendMessage("OnSelect", SendMessageOptions.DontRequireReceiver); PhotoCaptureFVTC pc = gameObject.GetComponent<PhotoCaptureFVTC>(); PhotoCapture.CreateAsync(false, pc.OnPhotoCaptureCreated); } }

PhotoCapture Class

`
using UnityEngine;
using System.Collections;
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()
{
    PhotoCapture.CreateAsync(false, OnPhotoCaptureCreated);
}

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

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

        photoCaptureObject.TakePhotoAsync(filePath, PhotoCaptureFileOutputFormat.JPG, OnCapturedPhotoToDisk);
        Debug.LogError("Saved That Image Somewhere" +filename + " " + filePath);
    }
    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");
    }
}

// Update is called once per frame
void Update()
{

}}

`

Answers

  • Options
    keljedkeljed ✭✭
    edited February 2017

    Haven't done that before but according to your code (as far as I understood) the picture taking process starts in the line

    captureObject.StartPhotoModeAsync(c, false, OnPhotoModeStarted);

    in the OnPhotoCaptureCreated method. Maybe you just store the capture object for later use and execute the above line in your tap event handler.

Sign In or Register to comment.