Beispiel #1
0
        // Configures the necessary {@link android.graphics.Matrix}
        // transformation to `_textureView`.
        // This method should be called after the camera preview size is determined in
        // setUpCameraOutputs and also the size of `_textureView` is fixed.

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

            if (null == _textureView || null == _previewSize || 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, _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);
            }
            _textureView.SetTransform(matrix);
        }
        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 = System.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);
        }
        /// <summary>
        /// Configures the necessary transformation to mTextureView.
        /// This method should be called after the camera preciew size is determined in openCamera, and also the size of mTextureView is fixed
        /// </summary>
        /// <param name="viewWidth">The width of mTextureView</param>
        /// <param name="viewHeight">VThe height of mTextureView</param>
        private void ConfigureTransform(int viewWidth, int viewHeight)
        {
            Activity activity = Activity;

            if (mTextureView == null || mPreviewSize == null || activity == null)
            {
                return;
            }

            SurfaceOrientation rotation = activity.WindowManager.DefaultDisplay.Rotation;
            Matrix             matrix   = new Matrix();
            RectF viewRect   = new RectF(0, 0, viewWidth, viewHeight);
            RectF bufferRect = new RectF(0, 0, mPreviewSize.Width, mPreviewSize.Height);
            float centerX    = viewRect.CenterX();
            float centerY    = viewRect.CenterY();

            if (rotation == SurfaceOrientation.Rotation90 || rotation == SurfaceOrientation.Rotation270)
            {
                bufferRect.Offset(centerX - bufferRect.CenterX(), centerY - 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, centerX, centerY);
                matrix.PostRotate(90 * ((int)rotation - 2), centerX, centerY);
            }
            mTextureView.SetTransform(matrix);
        }