Advertisement
Guest User

code

a guest
Dec 18th, 2018
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.44 KB | None | 0 0
  1. public void CapturePhotoAsync (OnCaptured callback) {
  2.         _callback = callback;
  3.  
  4.         PhotoCapture.CreateAsync(showHolograms, (_photoCapture) => {
  5.             this.photoCaptureObject = _photoCapture;
  6.             Resolution cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First();
  7.             //1280x720
  8.             targetTexture = new Texture2D(cameraResolution.width, cameraResolution.height);
  9.             cameraParameters = new CameraParameters();
  10.             cameraParameters.hologramOpacity = 0.0f;
  11.             cameraParameters.cameraResolutionWidth = cameraResolution.width;
  12.             cameraParameters.cameraResolutionHeight = cameraResolution.height;
  13.             cameraParameters.pixelFormat = CapturePixelFormat.BGRA32;
  14.  
  15.             //Activate the camera
  16.             photoCaptureObject.StartPhotoModeAsync(cameraParameters, onPhotoModeStarted);
  17.         });
  18.     }
  19.  
  20. void onPhotoModeStarted(PhotoCapture.PhotoCaptureResult result)
  21.     {
  22.         if (result.success)
  23.         {
  24.             //Take Picture
  25.             Debug.Log("Taking Foto...");
  26.             //photoCaptureObject.TakePhotoAsync(OnCapturedPhotoToMemory);
  27.             photoCaptureObject.TakePhotoAsync(putPhotoOnObject);
  28.         }
  29.         else
  30.         {
  31.             Debug.Log("Unable to start photo mode");
  32.         }
  33.     }
  34.  
  35.  
  36.  void putPhotoOnObject(PhotoCapture.PhotoCaptureResult result, PhotoCaptureFrame photoCaptureFrame)
  37.     {
  38.         if (!result.success)
  39.         {
  40.             Debug.LogError("Error CapturedPhotoToMemory");
  41.             return;
  42.         }
  43.         //Copy image data into the target texture
  44.         Debug.Log("Image to Texture");
  45.         photoCaptureFrame.UploadImageDataToTexture(targetTexture);
  46.  
  47.         //Create GameObject
  48.         Debug.Log("Create GameObhect");
  49.         GameObject quad = GameObject.CreatePrimitive(PrimitiveType.Quad);
  50.         Renderer quadRenderer = quad.GetComponent<Renderer>() as Renderer;
  51.         //quadRenderer.material = new Material(Shader.Find("Transparent/Diffuse"));
  52.         quadRenderer.material.color = Color.white;
  53.  
  54.         quad.transform.parent = this.transform;
  55.         quad.transform.localPosition = new Vector3(3.0f, 0.0f, 0.0f);
  56.         quad.AddComponent<Billboard>();
  57.  
  58.         quadRenderer.material.SetTexture("_MainTex", targetTexture);
  59.         Debug.Log("Object should exist");
  60.         photoCaptureObject.StopPhotoModeAsync(OnStoppedPhotoMode);
  61.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement