Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void CapturePhotoAsync (OnCaptured callback) {
- _callback = callback;
- PhotoCapture.CreateAsync(showHolograms, (_photoCapture) => {
- this.photoCaptureObject = _photoCapture;
- Resolution cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First();
- //1280x720
- targetTexture = new Texture2D(cameraResolution.width, cameraResolution.height);
- cameraParameters = new CameraParameters();
- cameraParameters.hologramOpacity = 0.0f;
- cameraParameters.cameraResolutionWidth = cameraResolution.width;
- cameraParameters.cameraResolutionHeight = cameraResolution.height;
- cameraParameters.pixelFormat = CapturePixelFormat.BGRA32;
- //Activate the camera
- photoCaptureObject.StartPhotoModeAsync(cameraParameters, onPhotoModeStarted);
- });
- }
- void onPhotoModeStarted(PhotoCapture.PhotoCaptureResult result)
- {
- if (result.success)
- {
- //Take Picture
- Debug.Log("Taking Foto...");
- //photoCaptureObject.TakePhotoAsync(OnCapturedPhotoToMemory);
- photoCaptureObject.TakePhotoAsync(putPhotoOnObject);
- }
- else
- {
- Debug.Log("Unable to start photo mode");
- }
- }
- void putPhotoOnObject(PhotoCapture.PhotoCaptureResult result, PhotoCaptureFrame photoCaptureFrame)
- {
- if (!result.success)
- {
- Debug.LogError("Error CapturedPhotoToMemory");
- return;
- }
- //Copy image data into the target texture
- Debug.Log("Image to Texture");
- photoCaptureFrame.UploadImageDataToTexture(targetTexture);
- //Create GameObject
- Debug.Log("Create GameObhect");
- GameObject quad = GameObject.CreatePrimitive(PrimitiveType.Quad);
- Renderer quadRenderer = quad.GetComponent<Renderer>() as Renderer;
- //quadRenderer.material = new Material(Shader.Find("Transparent/Diffuse"));
- quadRenderer.material.color = Color.white;
- quad.transform.parent = this.transform;
- quad.transform.localPosition = new Vector3(3.0f, 0.0f, 0.0f);
- quad.AddComponent<Billboard>();
- quadRenderer.material.SetTexture("_MainTex", targetTexture);
- Debug.Log("Object should exist");
- photoCaptureObject.StopPhotoModeAsync(OnStoppedPhotoMode);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement