Exemple #1
0
    private IEnumerator TakeSnapshotCoroutine()
    {
        Color32[] photoBuffer = null;

        yield return(null);

        photoBuffer = webCamTexture.GetPixels32();
        int width  = webCamTexture.width;
        int height = webCamTexture.height;

        // Apply device orientation
        if (Input.deviceOrientation == DeviceOrientation.LandscapeLeft)
        {
            photoBuffer = Color32Utils.RotateColorArrayRight(photoBuffer, width, height);
            int temp = width;
            width  = height;
            height = temp;
        }
        else if (Input.deviceOrientation == DeviceOrientation.LandscapeRight)
        {
            photoBuffer = Color32Utils.RotateColorArrayLeft(photoBuffer, width, height);
            int temp = width;
            width  = height;
            height = temp;
        }
        else if (Input.deviceOrientation == DeviceOrientation.PortraitUpsideDown)
        {
            photoBuffer = Color32Utils.RotateColorArrayRight(photoBuffer, width, height);
            photoBuffer = Color32Utils.RotateColorArrayRight(photoBuffer, height, width);
        }

        photoSFX.Play(cachedAudioSource);

        Debug.Log(string.Format("WebcamTexture size {0}x{1}", width, height));

        if (photoAngle == 0)
        {
            Texture2D texture = new Texture2D(width, height, TextureFormat.RGB24, false);
            texture.SetPixels32(photoBuffer);
            texture.Apply();
            DecoratorPanel.Instance.SetPhoto(texture);
        }
        else
        {
            Texture2D texture = new Texture2D(height, width, TextureFormat.RGB24, false);
            photoBuffer = Color32Utils.RotateColorArrayLeft(photoBuffer, width, height);
            texture.SetPixels32(photoBuffer);
            texture.Apply();
            DecoratorPanel.Instance.SetPhoto(texture);
        }

        decorator.Show();
        gameObject.SetActive(false);
    }
Exemple #2
0
    public void GetImageFromGallery()
    {
        newImagePanel.ShowProgress();

        NativeGalleryController.OpenGallery((Texture2D tex, ExifOrientation orientation) =>
        {
            if (tex != null)
            {
                // Deal with EXIF rotations
                Texture2D texture     = new Texture2D(tex.height, tex.width);
                Color32[] photoBuffer = texture.GetPixels32();

                switch (orientation)
                {
                case ExifOrientation.ORIENTATION_UNDEFINED: break;

                case ExifOrientation.ORIENTATION_NORMAL: break;

                case ExifOrientation.ORIENTATION_FLIP_HORIZONTAL: photoBuffer = Color32Utils.FlipColorArrayHorizontally(photoBuffer, tex.width, tex.height); break;

                case ExifOrientation.ORIENTATION_ROTATE_180: photoBuffer = Color32Utils.RotateColorArrayLeft(photoBuffer, tex.width, tex.height); Color32Utils.RotateColorArrayLeft(photoBuffer, tex.width, tex.height); break;

                case ExifOrientation.ORIENTATION_FLIP_VERTICAL: photoBuffer = Color32Utils.FlipColorArrayVertically(photoBuffer, tex.width, tex.height); break;

                case ExifOrientation.ORIENTATION_TRANSPOSE: photoBuffer = Color32Utils.RotateColorArrayLeft(photoBuffer, tex.width, tex.height); photoBuffer = Color32Utils.FlipColorArrayVertically(photoBuffer, tex.width, tex.height); break;

                case ExifOrientation.ORIENTATION_ROTATE_90: photoBuffer = Color32Utils.RotateColorArrayRight(photoBuffer, tex.width, tex.height); break;

                case ExifOrientation.ORIENTATION_TRANSVERSE: photoBuffer = Color32Utils.RotateColorArrayLeft(photoBuffer, tex.width, tex.height); photoBuffer = Color32Utils.FlipColorArrayHorizontally(photoBuffer, tex.width, tex.height); break;

                case ExifOrientation.ORIENTATION_ROTATE_270: photoBuffer = Color32Utils.RotateColorArrayLeft(photoBuffer, tex.width, tex.height); break;
                }

                texture.SetPixels32(photoBuffer);
                texture.Apply();

                SetPhoto(tex);
                DestroyImmediate(tex);
                Resources.UnloadUnusedAssets();
                System.GC.Collect();
            }
            newImagePanel.Hide();

            // Release old texture memory
        });
    }