/*protected override void OnDraw (Canvas canvas)
         * {
         *      base.OnDraw (canvas);
         *      paint.SetStyle(Paint.Style.Stroke);
         *      canvas.DrawCircle(point.X, point.Y, 50, paint);
         * }*/


        public override bool OnTouchEvent(MotionEvent e)
        {
            if (e.Action == MotionEventActions.Move)
            {
                if (surfaceHolder.Surface.IsValid)
                {
                    point.X = (int)e.GetX();
                    point.Y = (int)e.GetY();
                    Console.WriteLine("X " + point.X + " Y " + point.Y);

                    //Invalidate();
                    //return true;
                    Canvas canvas = surfaceHolder.LockCanvas();
                    canvas.DrawColor(Color.Black);
                    canvas.DrawCircle(point.X, point.Y, 60, paint);
                    surfaceHolder.UnlockCanvasAndPost(canvas);
                }
            }
            if (e.Action == MotionEventActions.Up)
            {
                if (surfaceHolder.Surface.IsValid)
                {
                    Canvas canvas = surfaceHolder.LockCanvas();
                    canvas.DrawColor(Color.Black);
                    //canvas.DrawCircle(point.X, point.Y, 100, paint);
                    surfaceHolder.UnlockCanvasAndPost(canvas);
                }
            }
            return(true);
        }
Exemplo n.º 2
0
        public void Run()
        {
            double oldXOrientation = xOrientation;
            double oldYOrientation = yOrientation;
            double stepFactor      = 0;

            var canvas = holder.LockCanvas();

            if (canvas != null)
            {
                stepFactor = GetStepFactor(canvas);
                holder.UnlockCanvasAndPost(canvas);
            }
            while (running)
            {
                // Don't draw too often, 100Hz should be enough.
                Thread.Sleep(10);

                // Only draw if changes are more than a pixel.

                if (Math.Abs(xOrientation - oldXOrientation) * stepFactor > 1 || Math.Abs(yOrientation - oldYOrientation) * stepFactor > 1)
                {
                    // remember where we draw.
                    oldXOrientation = xOrientation;
                    oldYOrientation = yOrientation;

                    canvas = holder.LockCanvas();
                    if (canvas != null)
                    {
                        DoDraw(canvas, stepFactor);
                        holder.UnlockCanvasAndPost(canvas);
                    }
                }
            }
        }
Exemplo n.º 3
0
        void clearDraw()
        {
            Canvas canvas = sh.LockCanvas();

            canvas.DrawColor(Color.Blue);
            sh.UnlockCanvasAndPost(canvas);
        }
        public void SurfaceChanged(ISurfaceHolder holder, [GeneratedEnum] Format format, int width, int height)
        {
            Canvas canvas = holder.LockCanvas();

            DrawGradation(canvas);
            holder.UnlockCanvasAndPost(canvas);
        }
Exemplo n.º 5
0
            // Draw one frame of the animation. This method gets called repeatedly
            // by posting a delayed Runnable. You can do any drawing you want in
            // here. This example draws a wireframe cube.
            void DrawFrame()
            {
                ISurfaceHolder holder = SurfaceHolder;

                Canvas c = null;

                try {
                    c = holder.LockCanvas();

                    if (c != null)
                    {
                        DrawCube(c);
                        DrawTouchPoint(c);
                    }
                } finally {
                    if (c != null)
                    {
                        holder.UnlockCanvasAndPost(c);
                    }
                }

                // Reschedule the next redraw
                mHandler.RemoveCallbacks(mDrawCube);

                if (is_visible)
                {
                    mHandler.PostDelayed(mDrawCube, 1000 / 25);
                }
            }
Exemplo n.º 6
0
            public override void Run()
            {
                Canvas canvas = null;

                while (_running)
                {
                    //if (_drawing)
                    //{
                    try
                    {
                        canvas = _surfaceHolder.LockCanvas(null);
                        if (canvas == null)
                        {
                            continue;
                        }

                        canvas.DrawColor(Color.Transparent, PorterDuff.Mode.Clear);
                        canvas.DrawBitmap(_fieldBitmap, 0, 0, null);
                        for (int idx = 0; idx < _drawableObjs.Count; idx++)
                        {
                            _drawItem = _drawableObjs[idx];
                            if (_drawItem.CurPosition == null)
                            {
                                continue;
                            }
                            IDrawableComponent drawable = _drawItem as IDrawableComponent;
                            if (drawable == null)
                            {
                                throw new InvalidCastException($"The drawable obj must be inherited from {nameof(IDrawableComponent)}");
                            }
                            canvas.DrawBitmap(drawable.Bitmap, _drawItem.CurPosition.X, _drawItem.CurPosition.Y, null);

                            //var list = _drawableObjs[listIdx];
                            //for (int drawObjIdx = 0; drawObjIdx < list.Count; drawObjIdx++)
                            //{
                            //    _drawItem = list[drawObjIdx];
                            //    if (_drawItem.CurPosition == null) continue;
                            //    IDrawableComponent drawable = _drawItem as IDrawableComponent;
                            //    if (drawable == null)
                            //        throw new InvalidCastException(
                            //            $"The drawable obj must be inherited from {nameof(IDrawableComponent)}");
                            //    canvas.DrawBitmap(drawable.Bitmap, _drawItem.CurPosition.X, _drawItem.CurPosition.Y,
                            //        null);
                            //}
                        }
                    }
                    catch (System.Exception e)
                    {
                        throw new System.Exception($"There is exception in Canvas field. {e}");
                    }
                    finally
                    {
                        if (canvas != null)
                        {
                            _surfaceHolder.UnlockCanvasAndPost(canvas);
                        }
                    }
                    //}
                }
            }
Exemplo n.º 7
0
        public void Run()
        {
            Rect dstRect   = new Rect();
            long startTime = Java.Lang.System.NanoTime();

            while (running)
            {
                if (!holder.Surface.IsValid)
                {
                    continue;
                }


                float deltaTime = (Java.Lang.System.NanoTime() - startTime) / 10000000.000f;
                startTime = Java.Lang.System.NanoTime();

                if (deltaTime > 3.15)
                {
                    deltaTime = (float)3.15;
                }


                game.getCurrentScreen().update(deltaTime);
                game.getCurrentScreen().paint(deltaTime);



                Canvas canvas = holder.LockCanvas();
                canvas.GetClipBounds(dstRect);
                canvas.DrawBitmap(framebuffer, null, dstRect, null);
                holder.UnlockCanvasAndPost(canvas);
            }
        }
Exemplo n.º 8
0
 public override void Run()
 {
     while (mRun)
     {
         Canvas c = null;
         try
         {
             c = mSurfaceHolder.LockCanvas(null);
             lock (mSurfaceHolder)
             {
                 if (mMode == STATE_RUNNING)
                 {
                     UpdatePhysics();
                 }
                 DoDraw(c);
             }
         }
         finally
         {
             // do this in a finally so that if an exception is thrown
             // during the above, we don't leave the Surface in an
             // inconsistent state
             if (c != null)
             {
                 mSurfaceHolder.UnlockCanvasAndPost(c);
             }
         }
     }
 }
        public void SurfaceCreated(ISurfaceHolder holder)
        {
            Canvas c = holder.LockCanvas(null);

            OnDraw(c);
            holder.UnlockCanvasAndPost(c);
        }
Exemplo n.º 10
0
        /// <summary>
        /// 在每次点击按钮的时候绘制坐标轴
        /// </summary>
        /// <param name="holder"></param>
        private void drawBack(ISurfaceHolder holder)
        {
            Canvas canvas = holder.LockCanvas();

            // 绘制白色背景
            canvas.DrawColor(Color.White);
            Paint p = new Paint();

            p.Color       = Color.Black;
            p.StrokeWidth = 2;
            // 绘制坐标轴
            canvas.DrawLine(X_OFFSET, centerY, WIDTH, centerY, p);
            canvas.DrawLine(X_OFFSET, 40, X_OFFSET, HEIGHT, p);
            holder.UnlockCanvasAndPost(canvas);
            holder.LockCanvas(new Rect(0, 0, 0, 0));
            holder.UnlockCanvasAndPost(canvas);
        }
Exemplo n.º 11
0
        public void SurfaceCreated(ISurfaceHolder holder)
        {
            this.holder = holder;

            var canvas = holder.LockCanvas();
            canvas.DrawColor(Android.Graphics.Color.Aquamarine);
            holder.UnlockCanvasAndPost(canvas);
        }
Exemplo n.º 12
0
        public override void Run()
        {
            while (mRun)
            {
                Canvas c = null;

                if (mState == GameState.Running)
                {
                    // Process any input and apply it to the game state
                    UpdateGameState();

                    if (!mJetPlaying)
                    {
                        mInitialized = false;

                        Log.Debug(TAG, "------> STARTING JET PLAY");

                        mJet.Play();
                        mJetPlaying = true;
                    }

                    mPassedTime = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;

                    // Kick off the timer task for counter update
                    // if not already initialized
                    if (mTimerTask == null)
                    {
                        mTimerTask = new CountDownTimerTask(this);

                        mTimer.Schedule(mTimerTask, mTaskIntervalInMillis);
                    }
                }
                else if (mState == GameState.Play && !mInitialized)
                {
                    SetInitialGameState();
                }
                else if (mState == GameState.Lost)
                {
                    mInitialized = false;
                }

                try {
                    c = mSurfaceHolder.LockCanvas(null);

                    lock (mSurfaceHolder)
                        DoDraw(c);
                } finally {
                    // do this in a finally so that if an exception is thrown
                    // during the above, we don't leave the Surface in an
                    // inconsistent state
                    if (c != null)
                    {
                        mSurfaceHolder.UnlockCanvasAndPost(c);
                    }
                }
            }
        }
Exemplo n.º 13
0
        public void StartAnimation()
        {
            if (holder == null)
            {
                return;
            }
            cancellationTokenSource = new CancellationTokenSource();
            var token = cancellationTokenSource.Token;

            Task.Run(() =>
            {
                var circularView = new PaletteOne(Activity);
                var paletteThree = new PaletteThree(Activity);
                var paletteTwo   = new PaletteTwo(Activity);
                var paletteFour  = new PaletteFour(Activity);
                var shadowFour   = new ShadowFour(Activity);
                var paletteFive  = new PaletteFive(Activity);
                while (!token.IsCancellationRequested)
                {
                    //draw on the canvas
                    Canvas canvas = null;

                    try
                    {
                        canvas = holder.LockCanvas();

                        circularView.Draw(canvas);

                        paletteThree.Draw(canvas);
                        paletteFive.Draw(canvas);
                        paletteTwo.Draw(canvas);
                        shadowFour.Draw(canvas);
                        paletteFour.Draw(canvas);


                        if (paletteFour.IsFinished)
                        {
                            break;
                        }
                    }
                    catch (Exception)
                    {
                        cancellationTokenSource.Cancel();
                        break;
                    }
                    finally
                    {
                        if (canvas != null)
                        {
                            holder.UnlockCanvasAndPost(canvas);
                        }
                    }
                }
            }, token);
        }
Exemplo n.º 14
0
        private void DrawFocusRect(ISurfaceHolder holder, float RectLeft, float RectTop, float RectRight, float RectBottom, Android.Graphics.Color color)
        {
            //lock
            var canvas = holder.LockCanvas();

            //no pointer to canvas?
            if (canvas == null)
            {
                return;
            }
            Log.Error(TAG, "\t\t --Drawing in canvas--");

            /*
             * Rectangle rect = new Rectangle((int)RectLeft, (int)RectTop, (int)RectRight, (int)RectBottom);
             * var xCenter = (rect.X + rect.Width) / 2;
             * var yCenter = (rect.Y + rect.Height) / 2;
             */
            //clear out
            canvas.Scale(vWidth / mPreviewSize.Width, vHeight / mPreviewSize.Height);

            if (CLEAR_CANVAS)
            {
                canvas.DrawColor(Android.Graphics.Color.Transparent, Android.Graphics.PorterDuff.Mode.Clear);
            }

            //border's properties
            var paint = new Android.Graphics.Paint();

            paint.SetStyle(Android.Graphics.Paint.Style.Stroke);

            var text = new Paint();

            text.TextSize  = 20;
            paint.TextSize = 30;

            //paint.SetTextSize(20);
            paint.Color       = color;
            paint.StrokeWidth = 3;
            canvas.DrawRect(RectLeft, RectTop, RectRight, RectBottom, paint);

            //DEBUG
            //canvas.DrawText("RectLeft:" + RectLeft, 0, 30, paint);
            //canvas.DrawText("RectTop:" + RectTop, 0, 60, paint);
            //canvas.DrawText("RectRight:" + RectRight, 0, 90, paint);
            //canvas.DrawText("RectBottom:" + RectBottom, 0, 120, paint);
            canvas.DrawText("Canvas:" + canvas.Width + "," + canvas.Height, 0, 30, paint);
            canvas.DrawText("Mat   :" + mPreviewSize.Width + "," + mPreviewSize.Height, 0, 60, paint);
            canvas.DrawText("View  :" + vWidth + "," + vHeight, 0, 90, paint);


            CLEAR_CANVAS = false;

            //unlock
            holder.UnlockCanvasAndPost(canvas);
        }
Exemplo n.º 15
0
 public void Run()
 {
     while (running)
     {
         var canvas = holder.LockCanvas();
         if (canvas != null)
         {
             DoDraw(canvas);
             holder.UnlockCanvasAndPost(canvas);
             Thread.Sleep(5);
         }
     }
 }
Exemplo n.º 16
0
        public void SurfaceChanged(ISurfaceHolder holder, int format, int w, int h)
        {
            this.holder = holder;

            if (width == w && height == h)
                return;
            width = view.RealWidth;
            height = view.RealHeight;
            rgb = new int[width * height];

            var canvas = holder.LockCanvas();
            canvas.DrawColor(Android.Graphics.Color.Crimson);
            holder.UnlockCanvasAndPost(canvas);
        }
Exemplo n.º 17
0
        void Draw(View view)
        {
            Canvas canvas;

            try {
                canvas = _holder.LockCanvas();
            } catch (Exception e) {
                return;
            }
            if (canvas != null)
            {
                view.Draw(canvas);
                _holder.UnlockCanvasAndPost(canvas);
            }
        }
Exemplo n.º 18
0
 public void OnDraw(int[] lines, bool flag)
 {
     myCanvas = myHolder.LockCanvas();
     if (myCanvas != null)
     {
         myCanvas.DrawColor(Color.Transparent, Mode.Clear);
         if (flag)
         {
             myCanvas.DrawLine(lines[0], lines[1], lines[2], lines[3], myPaint);
             myCanvas.DrawLine(lines[2], lines[3], lines[4], lines[5], myPaint);
             myCanvas.DrawLine(lines[4], lines[5], lines[6], lines[7], myPaint);
             myCanvas.DrawLine(lines[6], lines[7], lines[0], lines[1], myPaint);
         }
         myHolder.UnlockCanvasAndPost(myCanvas);
     }
 }
Exemplo n.º 19
0
            // Draw one frame of the animation. This method gets called repeatedly
            // by posting a delayed Runnable. You can do any drawing you want in
            // here. This example draws a wireframe cube.
            void DrawFrame()
            {
                if (SurfaceHolder == null)
                {
                    return;
                }
                ISurfaceHolder holder = SurfaceHolder;

                Canvas c = null;

                try
                {
                    c = holder.LockCanvas();

                    if (c != null)
                    {
                        DrawWallpaper(c);
                    }
                }
                finally
                {
                    if (c != null)
                    {
                        holder.UnlockCanvasAndPost(c);
                    }
                }

                // Reschedule the next redraw
                mHandler.RemoveCallbacks(mDrawCube);

                if (is_visible)
                {
                    if (clockView.FlowSecondHand)
                    {
                        mHandler.PostDelayed(mDrawCube, 1000 / 60);
                    }
                    else if (clockView.FlowMinuteHand)
                    {
                        mHandler.PostDelayed(mDrawCube, 1000 / 10);
                    }
                    else
                    {
                        mHandler.PostDelayed(mDrawCube, 1000 - lth.RealSunTime.Millisecond);
                    }
                }
            }
Exemplo n.º 20
0
        public void Start(ISurfaceHolder surfaceHolder)
        {
            try
            {
                if (_viewData == null)
                {
                    _viewData = new SurfaceViewData();
                }

                ISurfaceHolder holder = surfaceHolder;
                Canvas         canvas = null;

                _viewData.Start(() =>
                {
                    canvas = null;

                    try
                    {
                        canvas = holder.LockCanvas(null);
                        if (canvas != null)
                        {
                            Renderer.Render(canvas, View.Layers);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("{0}\n{1}", ex.Message, ex.StackTrace);
                    }
                    finally
                    {
                        if (canvas != null)
                        {
                            holder.UnlockCanvasAndPost(canvas);
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine("{0}\n{1}", ex.Message, ex.StackTrace);
            }
        }
        private void Render(double interpolate = 1)
        {
            if (!surfaceHolder.Surface.IsValid)
            {
                return;
            }

            Canvas canvas;

            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
            {
                canvas = surfaceHolder.LockHardwareCanvas();
            }
            else
            {
                canvas = surfaceHolder.LockCanvas();
            }
            canvas.DrawBitmap(background.Bitmap, background.X, background.Y, null);

            for (int i = 0; i < birds.Count; i++)
            {
                Bird bird = birds.ElementAt(i);
                canvas.DrawBitmap(bird.Bitmap, (float)(bird.X), bird.Y, null);
            }

            canvas.DrawBitmap(hero.Bitmap, (float)(hero.X), hero.Y, null);

            if (stones.Count > 0)
            {
                for (int i = 0; i < stones.Count; i++)
                {
                    Stone stone = stones.ElementAt(i);
                    // Interpolate is used to render object at place where player expects to see object,
                    // but not, where the object actually is!
                    canvas.DrawBitmap(stone.Bitmap, (float)(stone.X), (float)(stone.Y - (stone.Speed * interpolate)), null);
                }
            }

            canvas.DrawText(score.ToString(), 5, 35, scorePaint);

            surfaceHolder.UnlockCanvasAndPost(canvas);
        }
Exemplo n.º 22
0
        void Redraw(ISurfaceHolder holder)
        {
            int padding = size / pad_size_denom;
            int round   = size / round_size_denom;
            var canvas  = holder.LockCanvas();
            var paint   = new Paint()
            {
                Color = Color.White, StrokeWidth = 2
            };

            size = (int)Math.Min(canvas.Width / num_cols, canvas.Height / num_rows);
            for (int v = 0; v < num_cols; v++)
            {
                for (int h = 0; h < num_rows; h++)
                {
                    canvas.DrawRoundRect(padding + h * size, padding + v * size, (h + 1) * size - 2 * padding, (v + 1) * size - 2 * padding, round, round, paint);
                }
            }
            holder.UnlockCanvasAndPost(canvas);
        }
        public void Start(ISurfaceHolder surfaceHolder)
        {
            try
            {
                if (Service == null)
                {
                    Service = new SurfaceViewThread <InputArgs>();
                }

                ISurfaceHolder holder = surfaceHolder;
                Canvas         canvas = null;

                Service.Start((data) =>
                {
                    canvas = null;

                    try
                    {
                        HandleInput(data);
                        canvas = holder.LockCanvas(null);
                        this.DrawDiagram(canvas);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("{0}\n{1}", ex.Message, ex.StackTrace);
                    }
                    finally
                    {
                        if (canvas != null)
                        {
                            holder.UnlockCanvasAndPost(canvas);
                        }
                    }
                },
                              new InputArgs());
            }
            catch (Exception ex)
            {
                Console.WriteLine("{0}\n{1}", ex.Message, ex.StackTrace);
            }
        }
        private void MovePointMarker(MotionEvent e)
        {
            var canvas = surfaceHolder.LockCanvas();

            canvas.DrawColor(0, BlendMode.Clear);

            if (motion.beginX > -1)
            {
                canvas.DrawLine(motion.beginX, motion.beginY, e.GetX(), e.GetY(), surfacePaintOuter);
                canvas.DrawLine(motion.beginX, motion.beginY, e.GetX(), e.GetY(), surfacePaintInner);

                canvas.DrawCircle(motion.beginX, motion.beginY, SURFACE_RADIUS_OUTER / 2, surfacePaintOuter);
                canvas.DrawCircle(motion.beginX, motion.beginY, SURFACE_RADIUS_INNER / 2, surfacePaintInner);
            }
            if (e.Action != MotionEventActions.Up)
            {
                canvas.DrawCircle(e.GetX(), e.GetY(), SURFACE_RADIUS_OUTER, surfacePaintOuter);
                canvas.DrawCircle(e.GetX(), e.GetY(), SURFACE_RADIUS_INNER, surfacePaintInner);
            }
            surfaceHolder.UnlockCanvasAndPost(canvas);
        }
Exemplo n.º 25
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="xpos"></param>
        /// <param name="ypos"></param>
        public void Draw(float xpos, float ypos)
        {
            Canvas canvas = holder.LockCanvas();

            if (canvas != null)
            {
                canvas.DrawColor(Color.Transparent, PorterDuff.Mode.Clear);
                Paint paint = new Paint();
                paint.Color = Color.Blue;
                paint.SetStyle(Paint.Style.Stroke);
                paint.StrokeWidth = 4f;

                float radius = 50f;

                canvas.DrawCircle(xpos, ypos, radius, paint);



                holder.UnlockCanvasAndPost(canvas);
            }
        }
        private void DrawRectangle()
        {
            //define the paintbrush
            Paint mpaint = new Paint();

            mpaint.Color = new Color(ContextCompat.GetColor(Application.Context, Resource.Color.brand_dark));
            mpaint.SetStyle(Paint.Style.Stroke);
            mpaint.StrokeWidth = 5f;
            mpaint.SetPathEffect(new DashPathEffect(new float[] { 30, 20 }, 0));
            int paddingLeft = screenWidth / 20;
            int paddingTop  = screenHeight / 20;

            Canvas canvas = holder.LockCanvas();

            canvas.DrawColor(Color.Transparent, PorterDuff.Mode.Clear);
            Rect r = new Rect(paddingLeft, paddingTop, screenWidth - paddingLeft, screenHeight - paddingTop * 3);


            canvas.DrawRect(r, mpaint);
            holder.UnlockCanvasAndPost(canvas);
        }
Exemplo n.º 27
0
            void DrawFrame()
            {
                ISurfaceHolder holder = SurfaceHolder;
                Canvas         c      = null;

                try
                {
                    c = holder.LockCanvas();
                    if (c != null)
                    {
                        DrawIMG(c);
                        if (Settings.GetBoolean("show_touch", true) == true)
                        {
                            if (touch_point.X >= 0 && touch_point.Y >= 0)
                            {
                                var paint = new Paint();
                                paint.SetStyle(Paint.Style.Stroke);
                                paint.AntiAlias   = true;
                                paint.StrokeWidth = 2;
                                paint.Color       = Color.White;
                                paint.StrokeCap   = Paint.Cap.Round;
                                c.DrawCircle(touch_point.X, touch_point.Y, 80, paint);
                            }
                        }
                    }
                }
                finally
                {
                    if (c != null)
                    {
                        holder.UnlockCanvasAndPost(c);
                    }
                }
                mHandler.RemoveCallbacks(DrawIMGAction);
                if (is_visible)
                {
                    mHandler.PostDelayed(DrawIMGAction, 1000 / 20);
                }
            }
Exemplo n.º 28
0
        public void Run()
        {
            Rect dstRect   = new Rect();
            long startTime = Java.Lang.JavaSystem.NanoTime();

            while (_runnig)
            {
                if (!_holder.Surface.IsValid)
                {
                    continue;
                }

                float deltaTime = (Java.Lang.JavaSystem.NanoTime() - startTime) / 1000000000f;
                startTime = Java.Lang.JavaSystem.NanoTime();
                _game.CurrentScreen.Update(deltaTime);
                _game.CurrentScreen.Present(deltaTime);
                Canvas c = _holder.LockCanvas();
                c.GetClipBounds(dstRect);
                c.DrawBitmap(_frameBuffer, null, dstRect, null);
                _holder.UnlockCanvasAndPost(c);
            }
        }
    private void _surfaceView_Touch(object sender, View.TouchEventArgs e)
    {
        //define the paintbrush
        Paint mpaint = new Paint();

        mpaint.Color = Color.Red;
        mpaint.SetStyle(Paint.Style.Stroke);
        mpaint.StrokeWidth = 2f;

        //draw
        Canvas canvas = holder.LockCanvas();

        //clear the paint of last time
        canvas.DrawColor(Color.Transparent, PorterDuff.Mode.Clear);
        //draw a new one, set your ball's position to the rect here
        var  x = e.Event.GetX();
        var  y = e.Event.GetY();
        Rect r = new Rect((int)x, (int)y, (int)x + 100, (int)y + 100);

        canvas.DrawRect(r, mpaint);
        holder.UnlockCanvasAndPost(canvas);
    }
Exemplo n.º 30
0
        private void DrawFocusRect(ISurfaceHolder holder, float RectLeft, float RectTop, float RectRight, float RectBottom, Android.Graphics.Color color)
        {
            //lock
            var canvas = holder.LockCanvas();

            //no pointer to canvas?
            if (canvas == null)
            {
                return;
            }

            //detect face
            FaceEyes FE = Detect();

            //clear out
            canvas.DrawColor(Android.Graphics.Color.Transparent, Android.Graphics.PorterDuff.Mode.Clear);

            //border's properties
            var paint = new Android.Graphics.Paint();

            paint.SetStyle(Android.Graphics.Paint.Style.Stroke);
            paint.Color       = color;
            paint.StrokeWidth = 3;

            Rectangle e0 = FE.Eyes[0];
            Rectangle e1 = FE.Eyes[1];
            Rectangle f0 = FE.Faces[0];

            canvas.DrawRect(new Rect(e0.Left, e0.Top, e0.Right, e0.Bottom), paint);
            canvas.DrawRect(new Rect(e1.Left, e1.Top, e1.Right, e1.Bottom), paint);
            paint.Color = Android.Graphics.Color.White;
            canvas.DrawRect(new Rect(f0.Left, f0.Top, f0.Right, f0.Bottom), paint);

            //unlock
            holder.UnlockCanvasAndPost(canvas);
        }
Exemplo n.º 31
0
        void OnDetectionResultAquired(object sender, DarknetDetectionResult result)
        {
            var canvas = holderTransparent.LockCanvas();

            canvas.DrawColor(Android.Graphics.Color.Transparent, PorterDuff.Mode.Clear);
            //border's properties
            var paint = new Paint();

            paint.SetStyle(Paint.Style.Stroke);

            paint.StrokeWidth = 12;

            foreach (var obj in result.objects)
            {
                if (previewPage.UnderlyingService.FilteredClasses.Contains(obj.name))
                {
                    previewPage.ClassColors.TryGetValue(obj.name, out Xamarin.Forms.Color color);
                    paint.Color = color.ToAndroid();

                    Rect rect = new Rect((int)((obj.relative_Coordinates.center_x - obj.relative_Coordinates.width / 2) * transparentView.Width),
                                         (int)((obj.relative_Coordinates.center_y - obj.relative_Coordinates.height / 2) * transparentView.Height),
                                         (int)((obj.relative_Coordinates.center_x + obj.relative_Coordinates.width / 2) * transparentView.Width),
                                         (int)((obj.relative_Coordinates.center_y + obj.relative_Coordinates.height / 2) * transparentView.Height));

                    canvas.DrawRect(rect, paint);
                    canvas.DrawText(obj.name,
                                    (float)(obj.relative_Coordinates.center_x - obj.relative_Coordinates.width / 2) * transparentView.Width + 10,
                                    (float)(obj.relative_Coordinates.center_y - obj.relative_Coordinates.height / 2) * transparentView.Height + 50,
                                    new Paint()
                    {
                        Color = color.ToAndroid(), TextSize = 60
                    });
                }
            }
            holderTransparent.UnlockCanvasAndPost(canvas);
        }
        public void SurfaceCreated(ISurfaceHolder holder)
        {
            this.holder = holder;
            //畫筆定義
            Android.Graphics.Paint mpaint = new Android.Graphics.Paint();
            mpaint.Color = Android.Graphics.Color.Yellow;
            mpaint.SetStyle(Android.Graphics.Paint.Style.Stroke);
            mpaint.StrokeWidth = 4f;
            //畫布
            Android.Graphics.Canvas canvas = holder.LockCanvas();
            //清除畫布用
            canvas.DrawColor(Android.Graphics.Color.Transparent, Android.Graphics.PorterDuff.Mode.Clear);
            // 畫布長寬
            var w = sv_rec.Width;
            var h = sv_rec.Height;

            //控制正方形位置
            Android.Graphics.Rect r = new Android.Graphics.Rect((int)w / 16, (int)h / 8, (int)w / 16 + 7 * w / 8, (int)h / 8 + h / 2);

            //canvas.DrawRect(r, mpaint);   //正方形

            //左下框
            canvas.DrawRect(r.Left - 2, r.Bottom, r.Left + 50, r.Bottom + 2, mpaint);
            canvas.DrawRect(r.Left - 2, r.Bottom - 50, r.Left, r.Bottom, mpaint);
            //左上框
            canvas.DrawRect(r.Left - 2, r.Top - 2, r.Left + 50, r.Top, mpaint);
            canvas.DrawRect(r.Left - 2, r.Top, r.Left, r.Top + 50, mpaint);
            //右上框
            canvas.DrawRect(r.Right - 50, r.Top - 2, r.Right + 2, r.Top, mpaint);
            canvas.DrawRect(r.Right, r.Top, r.Right + 2, r.Top + 50, mpaint);
            //右下框
            canvas.DrawRect(r.Right - 50, r.Bottom, r.Right + 2, r.Bottom + 2, mpaint);
            canvas.DrawRect(r.Right, r.Bottom - 50, r.Right + 2, r.Bottom, mpaint);

            holder.UnlockCanvasAndPost(canvas);
        }