

Vector3 position = cameraToWorldMatrix.GetColumn(3) - cameraToWorldMatrix.GetColumn(2) PhotoCaptureFrame.TryGetCameraToWorldMatrix(out Matrix4x4 cameraToWorldMatrix)
#IS UNITY WEB PLAYER SAFE FOR LAPTOPS CODE#
To place this texture in the scene and display it using the locatable camera matrices, add the following code to OnCapturedPhotoToMemory in the result.success check: if (photoCaptureFrame.hasLocationData) Do as we wish with the texture such as apply it to a material, etc. PhotoCaptureFrame.UploadImageDataToTexture(targetTexture)

Copy the raw image data into our target texture Texture2D targetTexture = new Texture2D(cameraResolution.width, cameraResolution.height) Create our Texture2D for use and set the correct resolution void OnCapturedPhotoToMemory(PhotoCapture.PhotoCaptureResult result, PhotoCaptureFrame photoCaptureFrame)

You'll then apply your result to a texture and use the common clean-up code above. PhotoCaptureObject.TakePhotoAsync(OnCapturedPhotoToMemory) private void OnPhotoModeStarted(PhotoCapture.PhotoCaptureResult result) In OnPhotoModeStarted, capture a frame to memory. When capturing data to a Texture2D, the process is similar to capturing to disk. PhotoCaptureObject.StopPhotoModeAsync(OnStoppedPhotoMode) ĭebug.Log("Failed to save Photo to disk") Ĭapture a photo to a Texture2D with location PhotoCaptureObject.TakePhotoAsync(filePath, PhotoCaptureFileOutputFormat.JPG, OnCapturedPhotoToDisk) ĭebug.LogError("Unable to start photo mode!") Īfter capturing the photo to disk, exit photo mode and then clean up your objects void OnCapturedPhotoToDisk(PhotoCapture.PhotoCaptureResult result) String filePath = System.IO.Path.Combine(Application.persistentDataPath, filename) If you successfully started photo mode, take a photo and store it on disk private void OnPhotoModeStarted(PhotoCapture.PhotoCaptureResult result) The photo can be saved as a JPG or a PNG. The simplest operation is to capture a photo directly to a file. In the end, you'll also use the same clean-up code presented here void OnStoppedPhotoMode(PhotoCapture.PhotoCaptureResult result)Īfter these steps, you can choose which type of photo to capture. Resolution cameraResolution = ((res) => res.width * res.height).First() ĬameraParameters c = new CameraParameters() Ĭ.cameraResolutionWidth = cameraResolution.width Ĭ.cameraResolutionHeight = cameraResolution.height Ĭ.pixelFormat = CapturePixelFormat.BGRA32 ĬaptureObject.StartPhotoModeAsync(c, false, OnPhotoModeStarted) Void OnPhotoCaptureCreated(PhotoCapture captureObject) Next, store your object, set your parameters, and start Photo Mode private PhotoCapture photoCaptureObject = null PhotoCapture.CreateAsync(false, OnPhotoCaptureCreated) Start by creating a PhotoCapture object private void Start() Start Photo Mode via StartPhotoModeAsyncįor all three uses, start with the same first three steps above.Create a CameraParameters object with the settings you want.The general pattern for using PhotoCapture to take a photo is as follows: The PhotoCapture type allows you to take still photographs with the Photo Video Camera. Namespace (before Unity 2019): UnityEngine.XR.WSA.WebCam Available modes are photo, video, or none.

You can check which mode the camera is currently in with UnityEngine.XR. in Unity 2018 and earlier or in Unity 2019 and later. Only a single operation can occur with the camera at a time. In the "Publishing Settings > Capabilities" section, check the WebCam and Microphone capabilities.In the Unity Editor, go to the player settings by navigating to the "Edit > Project Settings > Player" page.The "WebCam" capability must be declared for an app to use the camera. In this article Enabling the capability for camera access
