Example #1
0
        // Configures the necessary matrix
        // transformation to `surfaceTextureView`.
        // This method should be called after the camera preview size is determined in
        // setUpCameraOutputs and also the size of `surfaceTextureView` is fixed.
        public void ConfigureTransform(int viewWidth, int viewHeight)
        {
            if (null == surfaceTextureView || null == previewSize)
            {
                return;
            }
            var    rotation   = (int)WindowManager.DefaultDisplay.Rotation;
            Matrix matrix     = new Matrix();
            RectF  viewRect   = new RectF(0, 0, viewWidth, viewHeight);
            RectF  bufferRect = new RectF(0, 0, previewSize.Height, previewSize.Width);
            float  centerX    = viewRect.CenterX();
            float  centerY    = viewRect.CenterY();

            if ((int)SurfaceOrientation.Rotation90 == rotation || (int)SurfaceOrientation.Rotation270 == rotation)
            {
                bufferRect.Offset(centerX - bufferRect.CenterX(), centerY - bufferRect.CenterY());
                matrix.SetRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.Fill);
                float scale = Math.Max((float)viewHeight / previewSize.Height, (float)viewWidth / previewSize.Width);
                matrix.PostScale(scale, scale, centerX, centerY);
                matrix.PostRotate(90 * (rotation - 2), centerX, centerY);
            }
            else if ((int)SurfaceOrientation.Rotation180 == rotation)
            {
                matrix.PostRotate(180, centerX, centerY);
            }
            surfaceTextureView.SetTransform(matrix);
        }
Example #2
0
        public void ConfigureTransform(int viewWidth, int viewHeight)
        {
            if (null == mTextureView || null == mPreviewSize)
            {
                return;
            }

            var windowManager = Context.GetSystemService(Context.WindowService).JavaCast <IWindowManager>();
            var rotation      = (int)windowManager.DefaultDisplay.Rotation;

            Matrix matrix     = new Matrix();
            RectF  viewRect   = new RectF(0, 0, viewWidth, viewHeight);
            RectF  bufferRect = new RectF(0, 0, mPreviewSize.Height, mPreviewSize.Width);
            float  centerX    = viewRect.CenterX();
            float  centerY    = viewRect.CenterY();

            if ((int)SurfaceOrientation.Rotation90 == rotation || (int)SurfaceOrientation.Rotation270 == rotation)
            {
                bufferRect.Offset(centerX - bufferRect.CenterX(), centerY - bufferRect.CenterY());
                matrix.SetRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.Fill);
                float scale = Java.Lang.Math.Max((float)viewHeight / mPreviewSize.Height, (float)viewWidth / mPreviewSize.Width);
                matrix.PostScale(scale, scale, centerX, centerY);
                matrix.PostRotate(90 * (rotation - 2), centerX, centerY);
            }
            else if ((int)SurfaceOrientation.Rotation180 == rotation)
            {
                matrix.PostRotate(180, centerX, centerY);
            }
            mTextureView.SetTransform(matrix);
        }
Example #3
0
        // Configures the necessary {@link android.graphics.Matrix}
        // transformation to `mTextureView`.
        // This method should be called after the camera preview size is determined in
        // setUpCameraOutputs and also the size of `mTextureView` is fixed.

        public void ConfigureTransform(int viewWidth, int viewHeight)
        {
            Activity activity = Activity;

            if (null == mTextureView || null == mPreviewSize || null == activity)
            {
                return;
            }
            var    rotation   = (int)activity.WindowManager.DefaultDisplay.Rotation;
            Matrix matrix     = new Matrix();
            RectF  viewRect   = new RectF(0, 0, viewWidth, viewHeight);
            RectF  bufferRect = new RectF(0, 0, mPreviewSize.Height, mPreviewSize.Width);
            float  centreX    = viewRect.CenterX();
            float  centreY    = viewRect.CenterY();

            switch (rotation)
            {
            case (int)SurfaceOrientation.Rotation90:
            case (int)SurfaceOrientation.Rotation270:
            {
                bufferRect.Offset(centreX - bufferRect.CenterX(), centreY - bufferRect.CenterY());
                matrix.SetRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.Fill);
                float scale = Math.Max((float)viewHeight / mPreviewSize.Height, (float)viewWidth / mPreviewSize.Width);
                matrix.PostScale(scale, scale, centreX, centreY);
                matrix.PostRotate(90 * (rotation - 2), centreX, centreY);
                break;
            }

            case (int)SurfaceOrientation.Rotation180:
                matrix.PostRotate(180, centreX, centreY);
                break;
            }
            mTextureView.SetTransform(matrix);
        }