コード例 #1
0
        void ConfigureTransform(int viewWidth, int viewHeight)
        {
            if (textureView == null || previewSize == null || Context == null)
            {
                return;
            }

            SurfaceOrientation rotation = (Context as Activity).WindowManager.DefaultDisplay.Rotation;

            Matrix matrix = new Matrix();

            if (rotation == SurfaceOrientation.Rotation90 || rotation == SurfaceOrientation.Rotation270)
            {
                RectF viewRect   = new RectF(0, 0, viewWidth, viewHeight);
                RectF bufferRect = new RectF(0, 0, previewSize.Width, previewSize.Height);

                bufferRect.Offset(viewRect.CenterX() - bufferRect.CenterX(), viewRect.CenterY() - bufferRect.CenterY());

                float scaleH = (float)viewHeight / previewSize.Width;
                float scaleW = scaleH * 4f / 3f * 4f / 3f;

                matrix.SetRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.Fill);
                matrix.PostRotate(90 * ((int)rotation - 2), viewRect.CenterX(), viewRect.CenterY());
                matrix.PostScale(scaleW, scaleH, viewRect.CenterX(), viewRect.CenterY());
            }

            textureView.SetTransform(matrix);
        }
コード例 #2
0
        /**
         * 绘制人脸框。
         *
         */
        private void showFrame(ImageFrame imageFrame, FaceInfo[] faceInfos)
        {
            Canvas canvas = textureView.LockCanvas();

            if (canvas == null)
            {
                textureView.UnlockCanvasAndPost(canvas);
                return;
            }
            if (faceInfos == null || faceInfos.Length == 0)
            {
                // 清空canvas
                canvas.DrawColor(Color.Transparent, PorterDuff.Mode.Clear);
                textureView.UnlockCanvasAndPost(canvas);
                return;
            }
            canvas.DrawColor(Color.Transparent, PorterDuff.Mode.Clear);

            FaceInfo faceInfo = faceInfos[0];


            rectF.Set(getFaceRect(faceInfo, imageFrame));

            // 检测图片的坐标和显示的坐标不一样,需要转换。
            previewView.mapFromOriginalRect(rectF);

            float yaw   = Math.Abs(faceInfo.HeadPose[0]);
            float patch = Math.Abs(faceInfo.HeadPose[1]);
            float roll  = Math.Abs(faceInfo.HeadPose[2]);

            if (yaw > 20 || patch > 20 || roll > 20)
            {
                // 不符合要求,绘制黄框
                paint.Color = Color.Yellow;

                String text  = "请正视屏幕";
                float  width = paint.MeasureText(text) + 50;
                float  x     = rectF.CenterX() - width / 2;
                paint.Color = Color.Red;
                paint.SetStyle(Paint.Style.Fill);
                canvas.DrawText(text, x + 25, rectF.Top - 20, paint);
                paint.Color = Color.Yellow;
            }
            else
            {
                // 符合检测要求,绘制绿框
                paint.Color = Color.Green;
            }
            paint.SetStyle(Paint.Style.Stroke);

            // 绘制框
            canvas.DrawRect(rectF, paint);
            textureView.UnlockCanvasAndPost(canvas);
        }
コード例 #3
0
        protected override void OnDraw(Canvas canvas)
        {
            var rect = new RectF(0, 0, canvas.Width, canvas.Height);
            var path = new Path();

            path.MoveTo(rect.CenterX(), rect.CenterY());
            path.AddArc(rect, _startAngle, _endAngle - _startAngle);
            path.LineTo(rect.CenterX(), rect.CenterY());
            path.Close();
            canvas.ClipPath(path);

            base.OnDraw(canvas);
        }
コード例 #4
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);
        }
コード例 #5
0
        //UPDATE: Return text limit
        private float DrawText(Canvas canvas, Paint paint,
                               string text, Paint.Align align, Color color, float offset,
                               RectF holderRect, Rect textRect)
        {
            paint.Color     = color;
            paint.TextAlign = align;
            paint.GetTextBounds(text, 0, text.Length, textRect);
            var   textWidth  = paint.MeasureText(text, 0, text.Length);
            float textLimitX = -1;

            float x = 0.0f;

            if (align == Paint.Align.Left) //Draw startText
            {
                x          = offset;
                textLimitX = x + textWidth;
            }
            else if (align == Paint.Align.Center)
            {
                x = holderRect.CenterX();
            }
            else if (align == Paint.Align.Right) //Draw endText
            {
                x          = holderRect.Right - offset;
                textLimitX = x - textWidth;
            }

            var y = holderRect.CenterY() + textRect.Height() / 2f - textRect.Bottom;

            canvas.DrawText(text.ToCharArray(), 0, text.Length, x, y, paint);

            return(textLimitX);
        }
コード例 #6
0
        private void configureTransform(int viewWidth, int viewHeight)
        {
            if (null == textureView || null == previewSize || null == context)
            {
                return;
            }
            int rotation = orientation;

            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 ( Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation)
            //{
            //    bufferRect.Offset(centerX - bufferRect.CenterX(), centerY - bufferRect.CenterY());
            //    matrix.SetRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.Fill);
            //    float scale = Java.Lang.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 (Surface.ROTATION_180 == rotation)
            //{
            //    matrix.PostRotate(180, centerX, centerY);
            //}
            textureView.SetTransform(matrix);
        }
コード例 #7
0
        /// <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>
        public void ConfigureTransform(int viewWidth, int viewHeight)
        {
            Activity activity = Activity;

            if (textureView == 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 = System.Math.Max((float)viewHeight / mPreviewSize.Height, (float)viewWidth / mPreviewSize.Width);
                matrix.PostScale(scale, scale, centerX, centerY);
                matrix.PostRotate(90 * ((int)rotation - 2), centerX, centerY);
            }
            textureView.SetTransform(matrix);
        }
コード例 #8
0
        private void ConfigureTransform(int viewWidth, int viewHeight)
        {
            if (this.SurfaceTexture == null || previewSize == null || this.Context == null)
            {
                return;
            }

            var windowManager = Context.GetSystemService(Context.WindowService).JavaCast <IWindowManager>();

            var rotation   = windowManager.DefaultDisplay.Rotation;
            var matrix     = new Matrix();
            var viewRect   = new RectF(0, 0, viewWidth, viewHeight);
            var bufferRect = new RectF(0, 0, previewSize.Width, previewSize.Height);

            var centerX = viewRect.CenterX();
            var 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);

                matrix.PostRotate(90 * ((int)rotation - 2), centerX, centerY);
            }

            this.SetTransform(matrix);
        }
コード例 #9
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 == _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 (rotation == (int)SurfaceOrientation.Rotation90 || rotation == (int)SurfaceOrientation.Rotation270)
            {
                bufferRect.Offset(centerX - bufferRect.CenterX(), centerY - bufferRect.CenterY());
                matrix.SetRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.Fill);
                float scale = JMath.Max((float)viewHeight / _previewSize.Height, (float)viewWidth / _previewSize.Width);
                matrix.PostScale(scale, scale, centerX, centerY);
                matrix.PostRotate(90 * (rotation - 2), centerX, centerY);
            }
            else if (rotation == (int)SurfaceOrientation.Rotation180)
            {
                matrix.PostRotate(180, centerX, centerY);
            }
            _textureView.SetTransform(matrix);
        }
コード例 #10
0
        public void ConfigureTransform(int viewWidth, int viewHeight)
        {
            //var activity = (Activity)_context;
            if (null == _surfaceView || null == _previewSize || null == _context)
            {
                return;
            }

            var windowManager = _context
                                .GetSystemService(Context.WindowService).JavaCast <IWindowManager>();

            ;
            var rotation   = (int)windowManager.DefaultDisplay.Rotation;
            var matrix     = new Matrix();
            var viewRect   = new RectF(0, 0, viewWidth, viewHeight);
            var bufferRect = new RectF(0, 0, _previewSize.Height, _previewSize.Width);
            var centerX    = viewRect.CenterX();
            var 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);
                var 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);
            }

            _surfaceView.SetTransform(matrix);
        }
コード例 #11
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);
        }
コード例 #12
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);
        }
コード例 #13
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)
        {
            var activity = MainActivity.context;

            if (null == mTextureView || null == mPreviewSize || null == activity)
            {
                return;
            }
            var rotation   = (int)activity.WindowManager.DefaultDisplay.Rotation;
            var matrix     = new Matrix();
            var viewRect   = new RectF(0, 0, viewWidth, viewHeight);
            var bufferRect = new RectF(0, 0, mPreviewSize.Height, mPreviewSize.Width);
            var centerX    = viewRect.CenterX();
            var 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);
                var scale = 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);
        }
コード例 #14
0
        public void configureTransform(int viewWidth, int viewHeight)
        {
            if (null == this || null == previewSize || null == activity.textureView)
            {
                return;
            }

            int   rotation   = (int)activity.WindowManager.DefaultDisplay.Rotation;
            var   matrix     = new Matrix();
            var   viewRect   = new RectF(0, 0, viewWidth, viewHeight);
            var   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 = System.Math.Max(
                    (float)viewHeight / previewSize.Height,
                    (float)viewHeight / 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);
            }
            activity.textureView.SetTransform(matrix);
        }
コード例 #15
0
        private void ConfigureTransform(int viewWidth, int viewHeight, int previewWidth, int previewHeight)
        {
            Matrix matrix     = new Matrix();
            RectF  viewRect   = new RectF(0, 0, viewWidth, viewHeight);
            RectF  bufferRect = new RectF(0, 0, previewWidth, previewHeight);
            float  centerX    = viewRect.CenterX();
            float  centerY    = viewRect.CenterY();

            bufferRect.Offset(centerX - bufferRect.CenterX(), centerY - bufferRect.CenterY());
            matrix.SetRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.Fill);
            float verticalScale = (float)viewHeight / previewHeight;

            //float horizontalScale = (float)viewWidth / previewWidth;
            //float scale = Math.Min(verticalScale, horizontalScale);

            ////this.tracer.Debug("ConfigureTransform: verticalScale={0}", verticalScale);
            ////this.tracer.Debug("ConfigureTransform: horizontalScale={0}", horizontalScale);
            ////this.tracer.Debug("ConfigureTransform: scale={0}", scale);
            ////this.tracer.Debug("ConfigureTransform: centerX={0}", centerX);
            ////this.tracer.Debug("ConfigureTransform: centerY={0}", centerY);

            matrix.PostScale(verticalScale, verticalScale, centerX, centerY);
            //matrix.PostRotate(90 * ((int)this.Rotation - 2), centerX, centerY);

            this.SetTransform(matrix);
        }
コード例 #16
0
        private void drawAlphaPanel(Canvas canvas)
        {
            /*
             * Will be drawn with hw acceleration, very fast.
             */

            if (!mShowAlphaPanel || mAlphaRect == null || mAlphaPattern == null)
            {
                return;
            }

            RectF rect = mAlphaRect;

            if (BORDER_WIDTH_PX > 0)
            {
                //TODO: cross check the color

                byte[] byteArr = BitConverter.GetBytes(mBorderColor);
                mBorderPaint.Color = Color.Argb(byteArr[0], byteArr[1], byteArr[2], byteArr[3]);
                //				mBorderPaint.Color = mBorderColor;
                canvas.DrawRect(rect.Left - BORDER_WIDTH_PX,
                                rect.Top - BORDER_WIDTH_PX,
                                rect.Right + BORDER_WIDTH_PX,
                                rect.Bottom + BORDER_WIDTH_PX,
                                mBorderPaint);
            }


            mAlphaPattern.Draw(canvas);

            float[] hsv    = new float[] { mHue, mSat, mVal };
            Color   color  = Color.HSVToColor(hsv);
            Color   acolor = Color.HSVToColor(0, hsv);

            mAlphaShader = new LinearGradient(rect.Left, rect.Top, rect.Right, rect.Top,
                                              color, acolor, Android.Graphics.Shader.TileMode.Clamp);


            mAlphaPaint.SetShader(mAlphaShader);

            canvas.DrawRect(rect, mAlphaPaint);

            if (mAlphaSliderText != null && !mAlphaSliderText.Equals(""))
            {
                canvas.DrawText(mAlphaSliderText, rect.CenterX(), rect.CenterY() + 4 * mDensity, mAlphaTextPaint);
            }

            float rectWidth = 4 * mDensity / 2;

            Point p = alphaToPoint(mAlpha);

            RectF r = new RectF();

            r.Left   = p.X - rectWidth;
            r.Right  = p.X + rectWidth;
            r.Top    = rect.Top - RECTANGLE_TRACKER_OFFSET;
            r.Bottom = rect.Bottom + RECTANGLE_TRACKER_OFFSET;

            canvas.DrawRoundRect(r, 2, 2, mHueAlphaTrackerPaint);
        }
コード例 #17
0
        /// <summary>
        ///     Configures the necessary transformation to autoFitTextureView.
        ///     This method should be called after the camera preciew size is determined in openCamera, and also the size of
        ///     autoFitTextureView is fixed
        /// </summary>
        /// <param name="viewWidth">The width of autoFitTextureView</param>
        /// <param name="viewHeight">VThe height of autoFitTextureView</param>
        private void ConfigureTransform(int viewWidth, int viewHeight)
        {
            Activity activity = this.Activity;

            if (this.autoFitTextureView == null || this.previewSize == null || activity == null)
            {
                this.tracer.Debug("ConfigureTransform: Could not perform transformation.");
                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, this.previewSize.Width, this.previewSize.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 verticalScale   = (float)viewHeight / this.previewSize.Height;
                float horizontalScale = (float)viewWidth / this.previewSize.Width;
                float scale           = Math.Max(verticalScale, horizontalScale);
                matrix.PostScale(scale, scale, centerX, centerY);
                matrix.PostRotate(90 * ((int)rotation - 2), centerX, centerY);
            }
            this.autoFitTextureView.SetTransform(matrix);
        }
コード例 #18
0
        /// <summary>
        /// Configures the transform.
        /// </summary>
        /// <param name="viewWidth">View width.</param>
        /// <param name="viewHeight">View height.</param>
        public void ConfigureTransform(int viewWidth, int viewHeight)
        {
            if (_viewSurface != null && _previewSize != null && _context != null)
            {
                var windowManager = _context.GetSystemService(Context.WindowService).JavaCast <IWindowManager>();

                var rotation   = windowManager.DefaultDisplay.Rotation;
                var matrix     = new Matrix();
                var viewRect   = new RectF(0, 0, viewWidth, viewHeight);
                var bufferRect = new RectF(0, 0, _previewSize.Width, _previewSize.Height);

                var centerX = viewRect.CenterX();
                var 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);

                    var scale = System.Math.Max((float)viewHeight / _previewSize.Height, (float)viewWidth / _previewSize.Width);
                    matrix.PostScale(scale, scale, centerX, centerY);
                    matrix.PostRotate(90 * ((int)rotation - 2), centerX, centerY);
                }

                _cameraTexture.SetTransform(matrix);
            }
        }
コード例 #19
0
        private void ConfigureTransform(int requestWidth, int requestHeight)
        {
            var viewRect   = new RectF(0, 0, requestHeight, requestWidth);
            var bufferRect = new RectF(0, 0, PixelSize.Height, PixelSize.Width);
            var centerX    = viewRect.CenterX();
            var centerY    = viewRect.CenterY();

            if ((int)SurfaceOrientation.Rotation90 == _rotation || (int)SurfaceOrientation.Rotation270 == _rotation)
            {
                Transform.TranslateX = centerX - bufferRect.CenterX();
                Transform.TranslateY = centerY - bufferRect.CenterY();
                var scale = Math.Max((float)requestWidth / PixelSize.Height, (float)requestHeight / PixelSize.Width);
                Transform.ScaleX        = scale;
                Transform.ScaleY        = scale;
                Transform.ScalePivotX   = centerX;
                Transform.ScalePivotY   = centerY;
                Transform.RotateDegrees = 90 * (_rotation - 2);
                Transform.RotatePivotX  = centerX;
                Transform.RotatePivotY  = centerY;
            }
            else if ((int)SurfaceOrientation.Rotation180 == _rotation)
            {
                Transform.RotateDegrees = 180;
                Transform.RotatePivotX  = centerX;
                Transform.RotatePivotY  = centerY;
            }
        }
コード例 #20
0
        // Resizing Behavior
        public static void resizingBehaviorApply(ResizingBehavior behavior, RectF rect, RectF target, RectF result)
        {
            if (rect.Equals(target) || target == null)
            {
                result.Set(rect);
                return;
            }

            if (behavior == ResizingBehavior.Stretch)
            {
                result.Set(target);
                return;
            }

            float xRatio = Math.Abs(target.Width() / rect.Width());
            float yRatio = Math.Abs(target.Height() / rect.Height());
            float scale  = 0f;

            switch (behavior)
            {
            case ResizingBehavior.AspectFit:
            {
                scale = Math.Min(xRatio, yRatio);
                break;
            }

            case ResizingBehavior.AspectFill:
            {
                scale = Math.Max(xRatio, yRatio);
                break;
            }

            case ResizingBehavior.Center:
            {
                scale = 1f;
                break;
            }
            }

            float newWidth  = Math.Abs(rect.Width() * scale);
            float newHeight = Math.Abs(rect.Height() * scale);

            result.Set(target.CenterX() - newWidth / 2,
                       target.CenterY() - newHeight / 2,
                       target.CenterX() + newWidth / 2,
                       target.CenterY() + newHeight / 2);
        }
コード例 #21
0
ファイル: MapView.cs プロジェクト: stijnthurkow/RunningApp
        /// <summary>
        /// Draw the current orientation on the canvas
        /// </summary>
        /// <param name="c">The canvas</param>
        protected void DrawOrientation(Canvas c)
        {
            // TODO: If no orientation is available, don't draw

            // If the current location is out of bound, don't draw
            if (!this.IsOnMap(this.CurrentRDLocation))
            {
                return;
            }

            // Determine the position of the CurrentLocation on the screen
            float x = (this.RD2Bitmap(this.CurrentRDLocation).X + this.MapOffsetX) * this.MapScale + this.Width / 2;
            float y = (this.RD2Bitmap(this.CurrentRDLocation).Y + this.MapOffsetY) * this.MapScale + this.Height / 2;

            // Calculate all the orientation triangle dimensions
            float TriangleWidth  = this.LocationRadius * 1.8f;
            float TriangleHeight = this.LocationRadius * 1f;

            float TriangleOffset = TriangleHeight * 0.2f;

            float TriangleBottomLeftX  = x - TriangleWidth / 2;
            float TriangleBottomRightX = x + TriangleWidth / 2;
            float TriangleTopX         = x;

            float TriangleBottomY = y + this.LocationRadius + TriangleOffset;
            float TriangleTopY    = TriangleBottomY + TriangleHeight;

            Path path = new Path();

            path.MoveTo(TriangleBottomLeftX, TriangleBottomY);
            path.LineTo(TriangleTopX, TriangleTopY);
            path.LineTo(TriangleBottomRightX, TriangleBottomY);
            path.LineTo(TriangleBottomLeftX, TriangleBottomY);
            path.Close();

            Paint z = new Paint();

            z.SetStyle(Paint.Style.Fill);
            z.Color = new Color(68, 94, 224);

            // Rotate the triangle the right way
            Matrix m = new Matrix();
            RectF  b = new RectF();

            path.ComputeBounds(b, true);

            b.Top -= TriangleOffset * 2 + TriangleHeight + this.LocationRadius * 2;

            float HeightWidthDifference = b.Height() - b.Width();

            b.Left  -= HeightWidthDifference / 2;
            b.Right += HeightWidthDifference / 2;

            // Draw orientation
            m.PostRotate(this.CurrentLocationRotation - 180, b.CenterX(), b.CenterY());
            path.Transform(m);

            c.DrawPath(path, z);
        }
コード例 #22
0
        public bool OnTouch(View v, MotionEvent ev)
        {
            bool handled = false;

            if (mZoomEnabled && HasDrawable((ImageView)v))
            {
                IViewParent parent = v.Parent;
                switch (ev.Action)
                {
                case MotionEventActions.Down:
                    // First, disable the Parent from intercepting the touch
                    // event
                    if (null != parent)
                    {
                        parent.RequestDisallowInterceptTouchEvent(true);
                    }
                    else
                    {
                        Log.Info(LOG_TAG, "onTouch getParent() returned null");
                    }

                    // If we're flinging, and the user presses down, cancel
                    // fling
                    CancelFling();
                    break;

                case MotionEventActions.Cancel:
                case MotionEventActions.Up:
                    // If the user has zoomed less than min scale, zoom back
                    // to min scale
                    if (GetScale() < mMinScale)
                    {
                        RectF rect = GetDisplayRect();
                        if (null != rect)
                        {
                            v.Post(new AnimatedZoomRunnable(this, GetScale(), mMinScale,
                                                            rect.CenterX(), rect.CenterY()));
                            handled = true;
                        }
                    }
                    break;
                }

                // Try the Scale/Drag detector
                if (null != mScaleDragDetector &&
                    mScaleDragDetector.OnTouchEvent(ev))
                {
                    handled = true;
                }

                // Check to see if the user double tapped
                if (null != mGestureDetector && mGestureDetector.OnTouchEvent(ev))
                {
                    handled = true;
                }
            }

            return(handled);
        }
コード例 #23
0
        private void RenderBack(Canvas canvas)
        {
            var Path       = new Path();
            var viewRadius = GetViewRadius();

            Path.AddCircle(drawingArea.CenterX(), drawingArea.CenterY(), viewRadius, Path.Direction.Ccw);
            canvas.DrawPath(Path, backStrokePaint);
        }
コード例 #24
0
        public void GetCenterPoint(out float x, out float y)
        {
            float ox   = -(translate.X / zoom);
            float oy   = -(translate.Y / zoom);
            var   rect = new RectF(ox, oy, ((float)this.SurfaceWidth / zoom) + ox, ((float)this.SurfaceHeight / zoom) + oy);

            x = rect.CenterX();
            y = rect.CenterY();
        }
コード例 #25
0
        private static BitmapDrawable GetCircleForProgress()
        {
            var conf = Bitmap.Config.Argb4444;

            if (_progressImage == null)
            {
                _progressImage = Bitmap.CreateBitmap(_windowSize.Width, _windowSize.Height, conf);
            }

            var canvas = new Canvas(_progressImage);
            var paint  = new Paint();

            paint.SetStyle(Paint.Style.Stroke);
            paint.StrokeWidth = 3;
            paint.AntiAlias   = true;
            paint.Color       = _colorToUse;
            canvas.DrawPaint(new Paint()
            {
                Color = Android.Graphics.Color.White
            });

            if (Progress > 20)
            {
                _activity.RunOnUiThread(() =>
                {
                    var ll = _layoutCenter.LayoutParameters;
                    if (ll.Height != _windowSize.Height)
                    {
                        ll.Height = _windowSize.Height;
                        _layoutCenter.LayoutParameters = ll;
                        _layoutCenter.RequestFocus();
                    }
                });

                canvas.DrawBitmap(_car, _zoneCircle.CenterX() - _car.Width / 2f, _zoneCircle.CenterY() - _car.Height / 2f, null);

                var startAngle    = -90f;
                var sweepingAngle = ((Progress - 20f) / 80f) * 360f;
                canvas.DrawArc(_zoneCircle, startAngle, sweepingAngle, false, paint);
            }
            else
            {
                _activity.RunOnUiThread(() =>
                {
                    var ll    = _layoutCenter.LayoutParameters;
                    ll.Height = (int)(((float)Progress / 20f) * _windowSize.Height);
                    _layoutCenter.LayoutParameters = ll;
                    _layoutCenter.RequestLayout();
                });
            }

            _layoutCenter.RequestLayout();
            return(new BitmapDrawable(_progressImage));
        }
コード例 #26
0
        private void DrawText(String text, Canvas c, RectF button, Paint p)
        {
            float textSize = 60;

            p.Color     = Color.White;
            p.AntiAlias = true;
            p.TextSize  = textSize;

            float textWidth = p.MeasureText(text);

            c.DrawText(text, button.CenterX() - (textWidth / 2), button.CenterY() + (textSize / 2), p);
        }
コード例 #27
0
        protected override void OnBoundsChange(Rect bounds)
        {
            base.OnBoundsChange(bounds);
            mRect.Set(margin, margin, bounds.Width() - margin, bounds.Height() - margin);

            if (useGradientOverlay)
            {
                var            colors   = new int[] { 0, 0, 0x7f000000 };
                var            pos      = new float[] { 0.0f, 0.7f, 1.0f };
                RadialGradient vignette = new RadialGradient(mRect.CenterX(),
                                                             mRect.CenterY() * 1.0f / 0.7f,
                                                             mRect.CenterX() * 1.3f,
                                                             colors,
                                                             pos, Shader.TileMode.Clamp);

                Matrix oval = new Matrix();
                oval.SetScale(1.0f, 0.7f);
                vignette.SetLocalMatrix(oval);

                paint.SetShader(new ComposeShader(bitmapShader, vignette, PorterDuff.Mode.SrcOver));
            }
        }
コード例 #28
0
        protected override void OnDraw(Canvas canvas)
        {
            if (mDisableCircularTransformation)
            {
                base.OnDraw(canvas);
                return;
            }

            if (mBitmap == null)
            {
                return;
            }

            if (mFillColor != Color.Transparent)
            {
                canvas.DrawCircle(mDrawableRect.CenterX(), mDrawableRect.CenterY(), mDrawableRadius, mFillPaint);
            }
            canvas.DrawCircle(mDrawableRect.CenterX(), mDrawableRect.CenterY(), mDrawableRadius, mBitmapPaint);
            if (mBorderWidth > 0)
            {
                canvas.DrawCircle(mBorderRect.CenterX(), mBorderRect.CenterY(), mBorderRadius, mBorderPaint);
            }
        }
        private void ConfigureTransform(int viewWidth, int viewHeight, int previewWidth, int previewHeight)
        {
            Matrix matrix     = new Matrix();
            RectF  viewRect   = new RectF(0, 0, viewWidth, viewHeight);
            RectF  bufferRect = new RectF(0, 0, previewWidth, previewHeight);
            float  centerX    = viewRect.CenterX();
            float  centerY    = viewRect.CenterY();

            bufferRect.Offset(centerX - bufferRect.CenterX(), centerY - bufferRect.CenterY());
            matrix.SetRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.Fill);
            float verticalScale = (float)viewHeight / previewHeight;

            matrix.PostScale(verticalScale, verticalScale, centerX, centerY);

            SetTransform(matrix);
        }
コード例 #30
0
        public Transition(RectF srcRect, RectF dstRect, long duration, IInterpolator interpolator)
        {
            if (!MathUtils.HaveSameAspectRatio(srcRect, dstRect))
            {
                throw new IncompatibleRatioException();
            }
            _mSrcRect      = srcRect;
            _mDstRect      = dstRect;
            _mDuration     = duration;
            _mInterpolator = interpolator;

            // Precomputes a few variables to avoid doing it in onDraw().
            _mWidthDiff   = dstRect.Width() - srcRect.Width();
            _mHeightDiff  = dstRect.Height() - srcRect.Height();
            _mCenterXDiff = dstRect.CenterX() - srcRect.CenterX();
            _mCenterYDiff = dstRect.CenterY() - srcRect.CenterY();
        }