Esempio n. 1
0
        Bitmap CreateRoundImage(Bitmap image)
        {
            var clipArea = Bitmap.CreateBitmap(image.Width, image.Height, Bitmap.Config.Argb8888);
            var canvas   = new Canvas(clipArea);
            var paint    = new Paint(PaintFlags.AntiAlias);

            canvas.DrawARGB(0, 0, 0, 0);
            canvas.DrawRoundRect(new RectF(0, 0, image.Width, image.Height), _iconRadius, _iconRadius, paint);


            paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcIn));

            var rect = new Android.Graphics.Rect(0, 0, image.Width, image.Height);

            canvas.DrawBitmap(image, rect, rect, paint);

            image.Recycle();
            image.Dispose();
            image = null;
            canvas.Dispose();
            canvas = null;
            paint.Dispose();
            paint = null;
            rect.Dispose();
            rect = null;

            return(clipArea);
        }
Esempio n. 2
0
 public void EndDrawHeaderText(Paint brush)
 {
     if (brush != null)
     {
         brush.Dispose();
     }
 }
 private void UpdatePaint()
 {
     if (_brush.Properties.ColorMode.CurrentValue == ColorType.Random && Paint == null)
     {
         Paint = new SKPaint {
             Color = SKColor.FromHsv(_brush.Rand.Next(0, 360), 100, 100)
         }
     }
     ;
     else if (_brush.Properties.ColorMode.CurrentValue == ColorType.Solid)
     {
         Paint?.Dispose();
         Paint = new SKPaint {
             Color = _brush.Properties.Color.CurrentValue
         };
     }
     else if (_brush.Properties.ColorMode.CurrentValue == ColorType.Gradient)
     {
         Paint?.Dispose();
         Paint = new SKPaint
         {
             Shader = SKShader.CreateRadialGradient(
                 Position,
                 Size,
                 _brush.Properties.Colors.BaseValue.GetColorsArray(),
                 _brush.Properties.Colors.BaseValue.GetPositionsArray(),
                 SKShaderTileMode.Clamp
                 )
         };
     }
 }
Esempio n. 4
0
        public override void Draw(Canvas canvas)
        {
            LoadResources ();

            var blackPaint = new Paint () { Color = black.Value };
            var whitePaint = new Paint () { Color = white.Value };

            XamGame.RenderBoard ((RectangleF rect, Square.ColourNames color) =>
            {
                var paint = color == Square.ColourNames.White ? whitePaint : blackPaint;
                canvas.DrawRect (rect.X, rect.Y, rect.Right, rect.Bottom, paint);

            }, (RectangleF rect, object image) =>
            {
                if (image != null)
                    canvas.DrawBitmap ((Bitmap) image, rect.Left, rect.Top, null);
            });

            // New Game button
            whitePaint.Color = white.Value;
            whitePaint.SetStyle (Paint.Style.Fill);
            whitePaint.TextSize = 30;
            whitePaint.AntiAlias = true;
            Rect bounds = new Rect ();
            whitePaint.GetTextBounds ("New Game", 0, 8, bounds);
            canvas.DrawText ("New Game", (this.Width - bounds.Width ()) / 2, this.Bottom - (XamGame.BoardUpperLeftCorner.Y - bounds.Height ()) / 2, whitePaint);

            whitePaint.Dispose ();
            blackPaint.Dispose ();

            base.Draw (canvas);
        }
Esempio n. 5
0
        /// <summary>
        /// Dispose of the Path and Paint
        /// </summary>
        public void Dispose()
        {
            if (Path != null)
            {
                Path.Dispose();

                Path = null;
            }

            if (Paint != null)
            {
                Paint.Dispose();

                Paint = null;
            }

            if (Resources != null)
            {
                foreach (var item in Resources)
                {
                    item.Dispose();
                }

                Resources = null;
            }
        }
Esempio n. 6
0
 protected override bool DrawChild(Android.Graphics.Canvas canvas, Android.Views.View child, long drawingTime)
 {
     try {
         var element     = (RoundedImage)Element;
         var radius      = Math.Min(Width, Height) / 2;
         var strokeWidth = 10;
         radius -= strokeWidth / 2;
         var path = new Path();
         path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);
         canvas.Save();
         canvas.ClipPath(path);
         var result = base.DrawChild(canvas, child, drawingTime);
         canvas.Restore();
         path = new Path();
         path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);
         var paint = new Paint();
         paint.AntiAlias   = true;
         paint.StrokeWidth = (float)element.BorderWidth;
         paint.SetStyle(Paint.Style.Stroke);
         paint.Color = element.BorderColor.ToAndroid();
         canvas.DrawPath(path, paint);
         paint.Dispose();
         path.Dispose();
         return(result);
     } catch (Exception ex) {
         Console.WriteLine(ex.Message);
     }
     return(base.DrawChild(canvas, child, drawingTime));
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="canvas"></param>
        /// <param name="child"></param>
        /// <param name="drawingTime"></param>
        /// <returns></returns>
        protected override bool DrawChild(Canvas canvas, Android.Views.View child, long drawingTime)
        {
            try
            {
                var radius = (float)((CircleImage)Element).CornerRadius;

                var borderThickness = (float)((CircleImage)Element).BorderThickness;

                int strokeWidth = 0;
                _bounds = new RectF(0, 0, Width, Height);
                if (borderThickness > 0)
                {
                    var logicalDensity = Xamarin.Forms.Forms.Context.Resources.DisplayMetrics.Density;
                    strokeWidth = (int)Math.Ceiling(borderThickness * logicalDensity + .5f);
                }


                var path = new Path();
                path.AddRoundRect(_bounds, radius, radius, Path.Direction.Ccw);
                canvas.Save();
                canvas.ClipPath(path);

                var paint = new Paint();
                paint.AntiAlias = true;
                paint.SetStyle(Paint.Style.Fill);
                paint.Color = ((CircleImage)Element).FillColor.ToAndroid();
                canvas.DrawPath(path, paint);
                paint.Dispose();


                var result = base.DrawChild(canvas, child, drawingTime);

                path.Dispose();
                canvas.Restore();

                path = new Path();
                path.AddRoundRect(_bounds, radius, radius, Path.Direction.Ccw);


                if (strokeWidth > 0.0f)
                {
                    paint             = new Paint();
                    paint.AntiAlias   = true;
                    paint.StrokeWidth = strokeWidth;
                    paint.SetStyle(Paint.Style.Stroke);
                    paint.Color = ((CircleImage)Element).BorderColor.ToAndroid();
                    canvas.DrawPath(path, paint);
                    paint.Dispose();
                }

                path.Dispose();
                return(result);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Unable to create circle image: " + ex);
            }

            return(base.DrawChild(canvas, child, drawingTime));
        }
Esempio n. 8
0
        protected override bool DrawChild(Canvas canvas, Android.Views.View child, long drawingTime)
        {
            try
            {
                //Clip Path
                var   radius = 25.0f;
                var   path   = new Path();
                RectF rect   = new RectF(0, 0, Width, Height);
                path.AddRoundRect(rect, radius, radius, Path.Direction.Cw);
                canvas.Save();
                canvas.ClipPath(path);
                var result = base.DrawChild(canvas, child, drawingTime);
                canvas.Restore();

                // Create Border
                path = new Path();
                path.AddRoundRect(rect, radius, radius, Path.Direction.Cw);
                var paint = new Paint();
                paint.AntiAlias   = true;
                paint.StrokeWidth = 1;
                paint.SetStyle(Paint.Style.Stroke);
                paint.Color = global::Android.Graphics.Color.Rgb(11, 11, 14);
                canvas.DrawPath(path, paint);

                //Clean Up
                paint.Dispose();
                path.Dispose();

                return(result);
            }
            catch
            {
                return(base.DrawChild(canvas, child, drawingTime));
            }
        }
Esempio n. 9
0
        private BitmapDescriptor GetCustomBitmapDescriptor(string iconName, int resourceID)
        {
            BitmapDescriptor icon;

            using (Paint paint = new Paint(PaintFlags.AntiAlias))
            {
                using (Rect bounds = new Rect())
                {
                    using (baseBitmap = BitmapFactory.DecodeResource(Resources, resourceID))
                    {
                        bitmap = baseBitmap.Copy(Bitmap.Config.Argb8888, true);

                        paint.GetTextBounds(iconName, 0, iconName.Length, bounds);

                        float x = bitmap.Width / 2.0f;
                        float y = (bitmap.Height - bounds.Height()) / 2.0f - bounds.Top;

                        Canvas canvas = new Canvas(bitmap);

                        canvas.DrawText(iconName, x, y, paint);

                        icon = BitmapDescriptorFactory.FromBitmap(bitmap);

                        bitmap.Dispose();
                        baseBitmap.Dispose();
                    }
                    bounds.Dispose();
                }
                paint.Dispose();
            }
            return(icon);
        }
 protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime)
 {
     try
     {
         var radius = Math.Min(Width, Height) / 2;
         var strokeWidth = 10;
         radius -= strokeWidth / 2;
         //Create path to clip
         var path = new Path();
         path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);
         canvas.Save();
         canvas.ClipPath(path);
         var result = base.DrawChild(canvas, child, drawingTime);
         canvas.Restore();
         // Create path for circle border
         path = new Path();
         path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);
         var paint = new Paint();
         paint.AntiAlias = true;
         paint.StrokeWidth = 5;
         paint.SetStyle(Paint.Style.Stroke);
         paint.Color = global::Android.Graphics.Color.White;
         canvas.DrawPath(path, paint);
         //Properly dispose
         paint.Dispose();
         path.Dispose();
         return result;
     }
     catch (Exception ex)
     {
         Console.WriteLine("Unable to create circle image: " + ex);
     }
     return base.DrawChild(canvas, child, drawingTime);
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="canvas"></param>
        /// <param name="child"></param>
        /// <param name="drawingTime"></param>
        /// <returns></returns>
        protected override bool DrawChild(Canvas canvas, Android.Views.View child, long drawingTime)
        {
            try
            {
                var radius = (float)Math.Min(Width, Height) / 2f;

                var borderThickness = ((CircleImage)Element).BorderThickness;

                float strokeWidth = 0f;

                if (borderThickness > 0)
                {
                    var logicalDensity = Context.Resources.DisplayMetrics.Density;
                    strokeWidth = (float)Math.Ceiling(borderThickness * logicalDensity + .5f);
                }

                radius -= strokeWidth / 2f;

                var path = new Path();
                path.AddCircle(Width / 2.0f, Height / 2.0f, radius, Path.Direction.Ccw);

                canvas.Save();
                canvas.ClipPath(path);

                var paint = new Paint
                {
                    AntiAlias = true
                };
                paint.SetStyle(Paint.Style.Fill);
                canvas.DrawPath(path, paint);
                paint.Dispose();

                var result = base.DrawChild(canvas, child, drawingTime);

                path.Dispose();
                canvas.Restore();

                path = new Path();
                path.AddCircle(Width / 2f, Height / 2f, radius, Path.Direction.Ccw);

                if (strokeWidth > 0.0f)
                {
                    paint             = new Paint();
                    paint.AntiAlias   = true;
                    paint.StrokeWidth = strokeWidth;
                    paint.SetStyle(Paint.Style.Stroke);
                    canvas.DrawPath(path, paint);
                    paint.Dispose();
                }

                path.Dispose();
                return(result);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Unable to create circle image: " + ex);
            }

            return(base.DrawChild(canvas, child, drawingTime));
        }
Esempio n. 12
0
        private void Render(Canvas canvas, IPin pin)
        {
            var paint = new Paint()
            {
                Color       = Color.Argb(0xFF, 0x00, 0x00, 0x00),
                StrokeWidth = (float)0.0,
                AntiAlias   = true,
                StrokeCap   = Paint.Cap.Butt
            };

            paint.SetStyle(Paint.Style.Fill);

            double x      = pin.Point.X - 4.0;
            double y      = pin.Point.Y - 4.0;
            double width  = 8.0;
            double height = 8.0;

            canvas.DrawOval(
                new RectF(
                    (float)x,
                    (float)y,
                    (float)(x + width),
                    (float)(y + height)),
                paint);

            paint.Dispose();
        }
Esempio n. 13
0
        protected override void OnDraw(Canvas canvas)
        {
            // clip the boundaries
            float radius = 10f;
            Path  path   = new Path();
            RectF rect   = new RectF(0f, 0f, this.Width, this.Height);

            path.AddRoundRect(rect, radius, radius, Path.Direction.Cw);
            canvas.ClipPath(path);

            base.OnDraw(canvas);
            //canvas.Restore();

            // add border
            path = new Path();
            path.AddRoundRect(rect, radius, radius, Path.Direction.Cw);

            var paint = new Paint();

            paint.AntiAlias   = true;
            paint.StrokeWidth = 2f;
            paint.SetStyle(Paint.Style.Stroke);
            paint.Color = global::Android.Graphics.Color.White;

            canvas.DrawPath(path, paint);

            // dispose
            paint.Dispose();
            path.Dispose();
        }
 protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime)
 {
     try
     {
         var radius      = Math.Min(Width, Height) / 2;
         var strokeWidth = 10;
         radius -= strokeWidth / 2;
         Path path = new Path();
         path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);
         canvas.Save();
         canvas.ClipPath(path);
         var result = base.DrawChild(canvas, child, drawingTime);
         canvas.Restore();
         path = new Path();
         path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);
         var paint = new Paint();
         paint.AntiAlias   = true;
         paint.StrokeWidth = 5;
         paint.SetStyle(Paint.Style.Stroke);
         paint.Color = global::Android.Graphics.Color.White;
         canvas.DrawPath(path, paint);
         paint.Dispose();
         path.Dispose();
         return(result);
     }
     catch (Exception ex)
     {
         var msg = ex.Message;
     }
     return(base.DrawChild(canvas, child, drawingTime));
 }
Esempio n. 15
0
        public virtual Icon GenerateIcon(T obj)
        {
            try
            {
                if (obj == null)
                {
                    return(null);
                }

                bmp = DrawableBitmap(obj);
                Icon icon = Icon.CreateWithBitmap(bmp);

                paint.Dispose();
                canvas.Dispose();
                bmp.Dispose();
                mutableBmp.Dispose();

                return(icon);
            }
            catch (System.Exception ex)
            {
                #region Logging
                LogRuntimeAttribute.InLogFiles(typeof(DrawableIcon <T>), ex);
                #endregion

                return(null);
            }
            finally { }
        }
Esempio n. 16
0
        private void Render(Canvas canvas, IRectangle rectangle)
        {
            var paint = new Paint()
            {
                Color       = ToNativeColor(rectangle.Stroke),
                StrokeWidth = (float)rectangle.StrokeThickness,
                AntiAlias   = true,
                StrokeCap   = Paint.Cap.Butt
            };

            paint.SetStyle(Paint.Style.Stroke);

            double x      = Math.Min(rectangle.Point1.X, rectangle.Point2.X);
            double y      = Math.Min(rectangle.Point1.Y, rectangle.Point2.Y);
            double width  = Math.Abs(rectangle.Point2.X - rectangle.Point1.X);
            double height = Math.Abs(rectangle.Point2.Y - rectangle.Point1.Y);

            canvas.DrawRect(
                (float)x,
                (float)y,
                (float)(x + width),
                (float)(y + height),
                paint);

            paint.Dispose();
        }
Esempio n. 17
0
        private void Render(Canvas canvas, IQuadraticBezier quadraticBezier)
        {
            var paint = new Paint()
            {
                Color       = ToNativeColor(quadraticBezier.Stroke),
                StrokeWidth = (float)quadraticBezier.StrokeThickness,
                AntiAlias   = true,
                StrokeCap   = Paint.Cap.Butt
            };

            paint.SetStyle(Paint.Style.Stroke);

            var path = new Path();

            path.SetLastPoint(
                (float)quadraticBezier.Start.X,
                (float)quadraticBezier.Start.Y);
            path.QuadTo(
                (float)quadraticBezier.Point1.X,
                (float)quadraticBezier.Point1.Y,
                (float)quadraticBezier.Point2.X,
                (float)quadraticBezier.Point2.Y);

            canvas.DrawPath(path, paint);

            path.Dispose();
            paint.Dispose();
        }
Esempio n. 18
0
        private void Render(Canvas canvas, IArc arc)
        {
            double x      = Math.Min(arc.Point1.X, arc.Point2.X);
            double y      = Math.Min(arc.Point1.Y, arc.Point2.Y);
            double width  = Math.Abs(arc.Point2.X - arc.Point1.X);
            double height = Math.Abs(arc.Point2.Y - arc.Point1.Y);

            if (width > 0.0 && height > 0.0)
            {
                var paint = new Paint()
                {
                    Color       = ToNativeColor(arc.Stroke),
                    StrokeWidth = (float)arc.StrokeThickness,
                    AntiAlias   = true,
                    StrokeCap   = Paint.Cap.Butt
                };
                paint.SetStyle(Paint.Style.Stroke);

                canvas.DrawArc(
                    new RectF(
                        (float)x,
                        (float)y,
                        (float)(x + width),
                        (float)(y + height)),
                    (float)arc.StartAngle,
                    (float)arc.SweepAngle,
                    false,
                    paint);

                paint.Dispose();
            }
        }
Esempio n. 19
0
        protected override bool DrawChild(Canvas canvas, Android.Views.View child, long drawingTime)
        {
            var radius      = Math.Min(Width, Height) / 2;
            var strokeWidth = 10;

            radius -= strokeWidth / 2;

            //Create path to clip
            var path = new Path();

            path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);
            canvas.Save();
            canvas.ClipPath(path);

            var result = base.DrawChild(canvas, child, drawingTime);

            canvas.Restore();

            // Create path for circle border
            path = new Path();
            path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);
            var paint = new Paint();

            paint.AntiAlias   = true;
            paint.StrokeWidth = 5;
            paint.SetStyle(Paint.Style.Stroke);
            paint.Color = Android.Graphics.Color.White;
            canvas.DrawPath(path, paint);

            //Properly dispose
            paint.Dispose();
            path.Dispose();

            return(result);
        }
Esempio n. 20
0
 protected override bool DrawChild(Canvas canvas, Android.Views.View child, long drawingTime)
 {
     try {
         var radius = Utilities.GetCornerRadius(Element);
         var rect   = new Rect(0, 0, Width, Height);
         var rectF  = new RectF(rect);
         var path   = new Path();
         path.AddRoundRect(rectF, radius, radius, Path.Direction.Ccw);
         canvas.Save();
         canvas.ClipPath(path);
         var paint = new Paint();
         paint.AntiAlias = true;
         paint.SetStyle(Paint.Style.Fill);
         canvas.DrawPath(path, paint);
         paint.Dispose();
         var result = base.DrawChild(canvas, child, drawingTime);
         path.Dispose();
         canvas.Restore();
         path = new Path();
         path.AddRoundRect(rectF, radius, radius, Path.Direction.Ccw);
         path.Dispose();
         return(result);
     }
     catch (Exception ex) {
         System.Diagnostics.Debug.WriteLine("Unable to create circle image: " + ex);
     }
     return(base.DrawChild(canvas, child, drawingTime));
 }
Esempio n. 21
0
        private void Render(Canvas canvas, IEllipse ellipse)
        {
            var paint = new Paint()
            {
                Color       = ToNativeColor(ellipse.Stroke),
                StrokeWidth = (float)ellipse.StrokeThickness,
                AntiAlias   = true,
                StrokeCap   = Paint.Cap.Butt
            };

            paint.SetStyle(Paint.Style.Stroke);

            double x      = Math.Min(ellipse.Point1.X, ellipse.Point2.X);
            double y      = Math.Min(ellipse.Point1.Y, ellipse.Point2.Y);
            double width  = Math.Abs(ellipse.Point2.X - ellipse.Point1.X);
            double height = Math.Abs(ellipse.Point2.Y - ellipse.Point1.Y);

            canvas.DrawOval(
                new RectF(
                    (float)x,
                    (float)y,
                    (float)(x + width),
                    (float)(y + height)),
                paint);

            paint.Dispose();
        }
        protected virtual void Dispose(bool disposing)
        {
            _disposed = true;

            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                SetShape(null, null);

                if (_clipPath != null)
                {
                    _clipPath?.Dispose();
                    _clipPath = null;
                }

                if (_maskPath != null)
                {
                    _maskPath.Dispose();
                    _maskPath = null;
                }

                if (_maskPaint != null)
                {
                    _maskPaint.Dispose();
                    _maskPaint = null;
                }
            }
        }
Esempio n. 23
0
        internal void DrawImage(
            global::Android.Graphics.Bitmap nativeBitmap,
            Rectangle destinationRectangle,
            Color tint)
        {
            if (null == nativeBitmap)
            {
                throw new ArgumentNullException(nameof(nativeBitmap));
            }

            var destinationRect = this.ToNativeRectFPixels(destinationRectangle);

            var paint = new Paint()
            {
                AntiAlias = true,
            };

            LightingColorFilter colorFilter = null;

            if ((!tint.IsTransparent) && (tint != Colors.White))
            {
                colorFilter = new LightingColorFilter(tint.ToAndroidColor(), 1);
                paint.SetColorFilter(colorFilter);
            }

            this._canvas.DrawBitmap(nativeBitmap, null, destinationRect, paint);

            paint.Dispose();
            colorFilter?.Dispose();
        }
Esempio n. 24
0
 private void Dispose(bool disposing)
 {
     if (disposing)
     {
         paintStroke.Dispose();
         paintFill.Dispose();
     }
 }
        public void RenderPoint(Canvas canvas, DataPoint dataPoint)
        {
            RadRect slot  = dataPoint.LayoutSlot;
            Paint   paint = this.CreatePaint(dataPoint);

            canvas.DrawRect((float)slot.GetX(), (float)slot.GetY(), (float)slot.Right, (float)slot.Bottom, paint);
            paint.Dispose();
        }
Esempio n. 26
0
        protected override bool DrawChild(Canvas canvas, View child, long drawingTime)
        {
            try
            {

                var radius = Math.Min(Width, Height) / 2;

                var borderThickness = (float)((CircleImage)Element).BorderThickness;

                int strokeWidth = 0;

                if (borderThickness > 0)
                {
                    var logicalDensity = Xamarin.Forms.Forms.Context.Resources.DisplayMetrics.Density;
                    strokeWidth = (int)Math.Ceiling(borderThickness * logicalDensity + .5f);
                }

                radius -= strokeWidth / 2;

                var path = new Path();
                path.AddCircle(Width / 2.0f, Height / 2.0f, radius, Path.Direction.Ccw);

                canvas.Save();
                canvas.ClipPath(path);

                var paint = new Paint();
                paint.AntiAlias = true;
                paint.SetStyle(Paint.Style.Fill);
                paint.Color = ((CircleImage)Element).FillColor.ToAndroid();
                canvas.DrawPath(path, paint);
                paint.Dispose();

                var result = base.DrawChild(canvas, child, drawingTime);

                canvas.Restore();

                path = new Path();
                path.AddCircle((float) Width / 2, (float) Height / 2, radius, Path.Direction.Ccw);

                if (strokeWidth > 0.0f)
                {
                    paint = new Paint {AntiAlias = true, StrokeWidth = strokeWidth};
                    paint.SetStyle(Paint.Style.Stroke);
                    paint.Color = ((CircleImage)Element).BorderColor.ToAndroid();
                    canvas.DrawPath(path, paint);
                    paint.Dispose();
                }

                path.Dispose();
                return result;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Unable to create circle image: " + ex);
            }

            return base.DrawChild(canvas, child, drawingTime);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="canvas"></param>
        /// <param name="child"></param>
        /// <param name="drawingTime"></param>
        /// <returns></returns>
        protected override bool DrawChild(Canvas canvas, Android.Views.View child, long drawingTime)
        {
            try
            {
                var radius      = Math.Min(Width, Height) / 2;
                var strokeWidth = ((CircleImage)Element).BorderThickness;
                radius -= strokeWidth / 2;



                var path = new Path();
                path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);


                canvas.Save();
                canvas.ClipPath(path);



                var paint = new Paint();
                paint.AntiAlias = true;
                paint.SetStyle(Paint.Style.Fill);
                paint.Color = ((CircleImage)Element).FillColor.ToAndroid();
                canvas.DrawPath(path, paint);
                paint.Dispose();


                var result = base.DrawChild(canvas, child, drawingTime);

                canvas.Restore();

                path = new Path();
                path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);


                var thickness = ((CircleImage)Element).BorderThickness;
                if (thickness > 0.0f)
                {
                    paint             = new Paint();
                    paint.AntiAlias   = true;
                    paint.StrokeWidth = thickness;
                    paint.SetStyle(Paint.Style.Stroke);
                    paint.Color = ((CircleImage)Element).BorderColor.ToAndroid();
                    canvas.DrawPath(path, paint);
                    paint.Dispose();
                }

                path.Dispose();
                return(result);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Unable to create circle image: " + ex);
            }

            return(base.DrawChild(canvas, child, drawingTime));
        }
        protected override bool DrawChild(Canvas canvas, Android.Views.View child, long drawingTime)
        {
            if (Element is null)
            {
                return(false);
            }
            RoundedShadowBoxView view = (RoundedShadowBoxView)Element;

            this.SetClipChildren(true);
            view.Padding = new Thickness(0, 0, 0, 0);
            int radius = (int)(view.RoundedCornerRadius);

            if (view.MakeCircle)
            {
                radius = Math.Min(Width, Height) / 2;
            }
            radius *= 2;

            try
            {
                var path = new Path();
                path.AddRoundRect(new RectF(0, 0, Width, Height), new float[] {
                    radius,
                    radius,
                    radius,
                    radius,
                    radius,
                    radius,
                    radius,
                    radius
                }, Path.Direction.Ccw);
                canvas.ClipPath(path);
                var result = base.DrawChild(canvas, child, drawingTime);

                canvas.Restore();

                if (view.BorderWidth > 0)
                {
                    // Draw a filled circle.
                    var paint = new Paint();
                    paint.AntiAlias   = true;
                    paint.StrokeWidth = view.BorderWidth;
                    paint.SetStyle(Paint.Style.Stroke);
                    paint.Color = view.BorderColor.ToAndroid();
                    canvas.DrawPath(path, paint);
                    paint.Dispose();
                }
                path.Dispose();
                return(result);
            }
            catch (Exception ex)
            {
                System.Console.Write(ex.Message);
            }

            return(base.DrawChild(canvas, child, drawingTime));
        }
        protected override void OnDestroy()
        {
            base.OnDestroy();

            if (_paint != null)
            {
                _paint.Dispose();
            }
        }
Esempio n. 30
0
        protected override void Dispose(bool disposing)
        {
            if (disposing && backgroundShape != null)
            {
                backgroundShape.Dispose();
                labelPaint.Dispose();
            }

            base.Dispose(disposing);
        }
Esempio n. 31
0
 /// <summary>
 /// Dispose the specified disposing.
 /// </summary>
 /// <returns>The dispose.</returns>
 /// <param name="disposing">If set to <c>true</c> disposing.</param>
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         _paint?.Dispose();
         _paint   = null;
         _context = null;
     }
     base.Dispose(disposing);
 }
Esempio n. 32
0
        public override void Draw(Canvas canvas)
        {
            try
            {
                var logicalDensity = _currentContext.Resources.DisplayMetrics.Density;

                var   radius          = ((CustomBoxView)Element).BorderRadius * logicalDensity;
                var   borderThickness = ((CustomBoxView)Element).BorderWidth;
                float strokeWidth     = 0f;

                if (borderThickness > 0)
                {
                    strokeWidth = (float)Math.Ceiling(borderThickness * logicalDensity + .5f);
                }
                radius -= strokeWidth / 2f;

                var path = new Path();
                path.AddRoundRect(new RectF(0, 0, Width - strokeWidth * 2, Height - strokeWidth * 2), radius, radius, Path.Direction.Ccw);

                canvas.Save();
                canvas.ClipPath(path);

                var paint = new Paint
                {
                    AntiAlias = true
                };
                paint.SetStyle(Paint.Style.Fill);
                paint.Color = ((CustomBoxView)Element).BackgroundColor.ToAndroid();
                canvas.DrawPath(path, paint);
                paint.Dispose();

                path.Dispose();
                canvas.Restore();

                path = new Path();
                path.AddRoundRect(new RectF(0, 0, Width - strokeWidth * 2, Height - strokeWidth * 2), radius, radius, Path.Direction.Ccw);

                if (strokeWidth > 0.0f)
                {
                    paint             = new Paint();
                    paint.AntiAlias   = true;
                    paint.StrokeWidth = strokeWidth;
                    paint.SetStyle(Paint.Style.Stroke);
                    paint.Color = ((CustomBoxView)Element).BorderColor.ToAndroid();
                    canvas.DrawPath(path, paint);
                    paint.Dispose();
                }

                path.Dispose();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Unable to create circle image: " + ex);
            }
        }
        protected override bool DrawChild(Canvas canvas, Android.Views.View child, long drawingTime)
        {
            if (Element is CounterIcon counterIcon && counterIcon.Counter != 0)
            {
                try
                {
                    //Add Focus
                    var paint = new Paint
                    {
                        Color = Android.Graphics.Color.Gray
                    };
                    paint.SetStyle(Paint.Style.Fill);
                    canvas.DrawCircle(canvas.Width / 2, canvas.Height / 2, canvas.Width / 2, paint);
                    canvas.Save();

                    //Add image
                    var result = base.DrawChild(canvas, child, drawingTime);
                    //canvas.Restore();

                    //Add Circle
                    paint = new Paint
                    {
                        Color = Android.Graphics.Color.Red
                    };
                    paint.SetStyle(Paint.Style.Fill);
                    canvas.DrawCircle(canvas.Width * 0.75f, canvas.Height / 4, canvas.Width / 4, paint);
                    canvas.Save();

                    //Add number
                    var number   = counterIcon.Counter < 10 ? $" {counterIcon.Counter} " : $"{counterIcon.Counter}";
                    var textSize = 8;
                    paint = new Paint(PaintFlags.AntiAlias)
                    {
                        TextAlign = Paint.Align.Center,
                        TextSize  = PixelsFromDp(textSize),
                        Color     = Android.Graphics.Color.White
                    };

                    var space           = (paint.Descent() + paint.Ascent()) / 2;
                    var horizontalSpace = paint.MeasureText(number, 0, 2) / 2;
                    canvas.DrawText(number, canvas.Width * 0.75f, canvas.Height / 4 - space, paint);
                    canvas.Save();

                    paint.Dispose();
                    return(result);
                }
                catch
                {
                    return(base.DrawChild(canvas, child, drawingTime));
                }
            }
            return(base.DrawChild(canvas, child, drawingTime));
        }
        /// <summary>
        /// Redraws the child.
        /// </summary>
        protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime)
        {
            try
            {
                var radius = (float)((RoundedImage)Element).BorderRadius;
                var stroke = (float)((RoundedImage)Element).BorderThickness;
                var delta = (float)stroke / 2.0f;

                if (radius < 0)
                {
                    radius = Math.Min(Width, Height) / 2.0f;
                }

                radius -= delta;

                // Clip with rounded rect
                var path = new Path();
                path.AddRoundRect(new RectF(delta, delta, Width - stroke, Height - stroke),
                    radius, radius, Path.Direction.Ccw);
                canvas.Save();
                canvas.ClipPath(path);
                path.Dispose();

                var result = base.DrawChild(canvas, child, drawingTime);

                canvas.Restore();

                // Add stroke for smoother border
                path = new Path();
                path.AddRoundRect(new RectF(delta, delta, Width - stroke, Height - stroke),
                    radius, radius, Path.Direction.Ccw);
                var paint = new Paint();
                paint.AntiAlias = true;
                paint.StrokeWidth = stroke;
                paint.SetStyle(Paint.Style.Stroke);
                paint.Color = ((RoundedImage)Element).BorderColor.ToAndroid();
                canvas.DrawPath(path, paint);
                paint.Dispose();

                // Clean up
                path.Dispose();

                return result;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Unable to create circle image: " + ex);
            }

            return base.DrawChild(canvas, child, drawingTime);
        }
		/// <Docs>The Canvas to which the View is rendered.</Docs>
		/// <summary>
		/// Draw the specified canvas.
		/// </summary>
		/// <param name="canvas">Canvas.</param>
		public override void Draw (Canvas canvas)
		{			
			try
			{
				var element = Element as RoundCornerView;
				var cornerRadius = (float)element.CornerRadius*Resources.DisplayMetrics.Density;

				// Paint rounded rect itself
				canvas.Save();
				var paint = new Paint();
				paint.AntiAlias = true;
				var strokeWidth = (((float)element.BorderWidth)*Resources.DisplayMetrics.Density);
				paint.StrokeWidth = strokeWidth;

				if(element.BackgroundColor != Xamarin.Forms.Color.Transparent)
				{
					paint.SetStyle(Paint.Style.Fill);
					paint.Color = element.BackgroundColor.ToAndroid();
					canvas.DrawRoundRect(new RectF(0, 0, Width, Height), cornerRadius, cornerRadius, paint);
				}

				if(element.BorderColor != Xamarin.Forms.Color.Transparent)
				{
					paint.SetStyle(Paint.Style.Stroke);
					paint.Color = element.BorderColor.ToAndroid();
					canvas.DrawRoundRect(new RectF(0, 0, Width, Height), cornerRadius, cornerRadius, paint);
				}

				//Properly dispose
				paint.Dispose();
				canvas.Restore();

				// Create clip path
				var path = new Path();
				path.AddRoundRect(new RectF(0.0f + (strokeWidth/2), 0.0f + (strokeWidth/2), 
					Width - (strokeWidth/2), Height - (strokeWidth/2)), cornerRadius, cornerRadius, Path.Direction.Cw);
				
				canvas.Save();
				canvas.ClipPath(path);

				// Do base drawing
				for(var i=0; i<ChildCount; i++)
					GetChildAt(i).Draw(canvas);

				canvas.Restore();
				path.Dispose();
			}
			catch (Exception)
			{				
			}				
		}
        public override void Draw(Canvas canvas)
        {
            Rect rectangle = new Rect();
            GetDrawingRect(rectangle);

            Paint paint = new Paint();
            paint.AntiAlias = true;
            paint.Color = Color.Gray;
            paint.SetStyle(Paint.Style.Stroke);
            canvas.DrawLine(rectangle.Left, rectangle.Bottom - 2, rectangle.Right, rectangle.Bottom, paint);

            paint.Dispose();

            base.Draw(canvas);
        }
        /// <Docs>The Canvas to which the View is rendered.</Docs>
        /// <summary>
        /// Draw the specified canvas.
        /// </summary>
        /// <param name="canvas">Canvas.</param>
        public override void Draw(Android.Graphics.Canvas canvas)
        {  
            base.Draw(canvas);

            var paintForAngle = new Paint { Color = (Android.Graphics.Color.White), TextSize = 37f };
            paintForAngle.SetStyle(Paint.Style.Stroke);
            paintForAngle.SetTypeface(Typeface.CreateFromAsset(Forms.Context.Assets, "Fonts/fontawesome.ttf"));

            canvas.DrawText('\uf078'.ToString(), (float)(canvas.ClipBounds.CenterX() * 1.65), (float)(canvas.ClipBounds.CenterY() * 1.15), paintForAngle);


            #region Disposing 
            paintForAngle.Dispose();
            canvas.Dispose();
            #endregion
        }
        protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime)
        {
            try {
                // Extract properties
                var source = (CircularImage)Element;
                var borderWidth = source.BorderWidth;
                var borderColor = source.BorderColor.ToAndroid();

                var radius = Math.Min(Width, Height) / 2;
                var strokeWidth = 10;
                radius -= strokeWidth / 2;

                //Create path to clip
                var path = new Path();
                path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);
                canvas.Save();
                canvas.ClipPath(path);

                var result = base.DrawChild(canvas, child, drawingTime);

                canvas.Restore();

                // Create path for circle border
                path = new Path();
                path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);

                var paint = new Paint();
                paint.AntiAlias = true;
                paint.StrokeWidth = borderWidth;
                paint.SetStyle(Paint.Style.Stroke);
                paint.Color = borderColor;

                canvas.DrawPath(path, paint);

                //Properly dispose
                paint.Dispose();
                path.Dispose();
                return result;
            } catch (Exception ex) {
                System.Diagnostics.Debug.WriteLine("Unable to create circle image: " + ex);
            }

            return base.DrawChild(canvas, child, drawingTime);
        }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="canvas"></param>
    /// <param name="child"></param>
    /// <param name="drawingTime"></param>
    /// <returns></returns>
    protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime)
    {
      try
      {
        var radius = Math.Min(Width, Height) / 2;
        var strokeWidth = 10;
        radius -= strokeWidth / 2;


        Path path = new Path();
        path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);
        canvas.Save();
        canvas.ClipPath(path);

        var result = base.DrawChild(canvas, child, drawingTime);

        canvas.Restore();

        path = new Path();
        path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);

        var paint = new Paint();
        paint.AntiAlias = true;
        paint.StrokeWidth = ((CircleImage)Element).BorderThickness;
        paint.SetStyle(Paint.Style.Stroke);
        paint.Color = ((CircleImage)Element).BorderColor.ToAndroid();

        canvas.DrawPath(path, paint);

        paint.Dispose();
        path.Dispose();
        return result;
      }
      catch (Exception ex)
      {
        System.Diagnostics.Debug.WriteLine("Unable to create circle image: " + ex);
      }

      return base.DrawChild(canvas, child, drawingTime);
    }
		protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime)
		{
			try
			{
				var radius = Math.Min(Width, Height) / 2;
				var strokeWidth = 10;
				radius -= strokeWidth / 2;


				Path path = new Path();
				path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);
				canvas.Save();
				canvas.ClipPath(path);

				var result = base.DrawChild(canvas, child, drawingTime);

				canvas.Restore();

				path = new Path();
				path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);

				var paint = new Paint();
				paint.AntiAlias = true;
				paint.StrokeWidth = 5;
				paint.SetStyle(Paint.Style.Stroke);
				paint.Color = global::Android.Graphics.Color.White;

				canvas.DrawPath(path, paint);

				paint.Dispose();
				path.Dispose();
				return result;
			}
			catch (Exception ex)
			{
			}

			return base.DrawChild(canvas, child, drawingTime);
		}
 protected override bool DrawChild(Android.Graphics.Canvas canvas, Android.Views.View child, long drawingTime)
 {
     try
     {
         var element = (RoundedImage)Element;
         var radius = Math.Min(Width, Height) / 2;
         var strokeWidth = 10;
         radius -= strokeWidth / 2;
         //Create path to clip
         var path = new Path();
         path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);
         canvas.Save();
         canvas.ClipPath(path);
         var result = base.DrawChild(canvas, child, drawingTime);
         canvas.Restore();
         // Create path for circle border
         path = new Path();
         path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);
         var paint = new Paint();
         paint.AntiAlias = true;
         //TODO look for a correct way to assign the BorderWidth depending of the screen dpi
         paint.StrokeWidth = (float)element.BorderWidth;
         paint.SetStyle(Paint.Style.Stroke);
         paint.Color = element.BorderColor.ToAndroid();
         canvas.DrawPath(path, paint);
         //Properly dispose
         paint.Dispose();
         path.Dispose();
         return result;
     }
     catch (Exception ex)
     {
         //Why this happend
         Console.WriteLine(ex.Message);
     }
     return base.DrawChild(canvas, child, drawingTime);
 }
Esempio n. 42
0
        //--------------------------------------------------------------
        // EVENT METHODS
        //--------------------------------------------------------------
        // Draw every proposed piece in the accorded space
        // each piece have the space for 5 blocks to draw itself on the width
        // On the Height, each piece have 4 blocks to draw itself and there is one pixel to separate each one of them (because there is less space on the height)
        protected override void OnDraw(Canvas canvas)
        {
            base.OnDraw(canvas);

            // If it is the first draw, calculate the size of the block according to the size of the canvas
            if(_blockSize == 0)
            {
                // Calculate the size of the block, Space for each piece set to 5 blocks (except for the last one)
                _blockSize = Math.Min((Width - (_nbPieceByLine - 1) * StrokeWidthBorder)/(_nbPieceByLine*5),
                                        (Height - (Constants.NbLinePropPiece - 1) * StrokeWidthBorder)/(Constants.NbLinePropPiece*5));

                // Create the blocks images with the right size
                foreach(TetrisColor color in Enum.GetValues(typeof(TetrisColor)))
                {
                    Bitmap image = BlockView.CreateImage(_blockSize, color);
                    if(image != null)
                    {
                        _blockImages.Add(color, image);
                    }
                }

                _offset = new Point((Width - _nbPieceByLine*5*_blockSize - (_nbPieceByLine - 1) * StrokeWidthBorder) / 2,
                                    (Height - Constants.NbLinePropPiece*5*_blockSize - (Constants.NbLinePropPiece - 1) * StrokeWidthBorder) / 2);
            }

            // Draw the pieces and highlight the selected one
            for(int i = 0; i < Constants.NbProposedPiece; i++)
            {
                if(_proposedPieces[i] != null)
                {
                    // Show the selected piece
                    if(i == _selectedPiece)
                    {
                        int left = ((i % _nbPieceByLine) == 0) ? 0 : _offset.X;
                        int right = (((i + 1) % _nbPieceByLine) == 0) ? Width : _offset.X;
                        int top = ((i / _nbPieceByLine) == 0) ? 0 : _offset.Y;
                        int bottom = (i >= (_nbPieceByLine * (Constants.NbLinePropPiece - 1))) ? Height : _offset.Y;

                        RectF rect = new RectF((i % _nbPieceByLine) * _blockSize * 5 + (i % _nbPieceByLine) * StrokeWidthBorder + left,
                                                (_blockSize * 5) * (i / _nbPieceByLine) + (i / _nbPieceByLine) * StrokeWidthBorder + top,
                                                ((i % _nbPieceByLine) + 1) * _blockSize * 5 + (i % _nbPieceByLine) * StrokeWidthBorder + right,
                                                (_blockSize * 5) * (1 + i / _nbPieceByLine) + (i / _nbPieceByLine) * StrokeWidthBorder + bottom);

                        Paint paint = new Paint {AntiAlias = true, Color = Utils.getAndroidReallyLightColor(TetrisColor.Red)};
                        //canvas.DrawRoundRect(rect, Constants.RadiusHighlight, Constants.RadiusHighlight, paint);
                        canvas.DrawRect(rect, paint);
                        paint.Dispose();
                    }
                    float xSize = 0;
                    float ySize = 0;
                    _proposedPieces[i].GetDrawnSize(_blockSize, ref xSize, ref ySize);

                    // Draw each piece
                    _proposedPieces[i].Draw(canvas, _blockSize, _blockImages,
                        (i % _nbPieceByLine) * _blockSize * 5 + (_blockSize * 5 - xSize) / 2 + _offset.X + (i % _nbPieceByLine) * StrokeWidthBorder,
                        Height - ((i / _nbPieceByLine + 1) * _blockSize * 5 - (_blockSize * 5 - ySize) / 2 + _offset.Y + (i / _nbPieceByLine) * StrokeWidthBorder),
                        Height);
                }
            }

            // Grid
            for(int i = 1; i < _nbPieceByLine; i++)
            {
                // Vertical
                int x = _offset.X + i*5*_blockSize + (i - 1) * StrokeWidthBorder;
                canvas.DrawRect(x, 0, x + StrokeWidthBorder, Height, GridPaint);
            }
            for(int i = 1; i < Constants.NbLinePropPiece; i++)
            {
                // Horizontal
                int y = _offset.Y + i*5*_blockSize + (i - 1) * StrokeWidthBorder;
                canvas.DrawRect(0, y, Width, y + StrokeWidthBorder, GridPaint);
            }
        }
Esempio n. 43
0
        public void Draw(Canvas canvas, float blockSize, Dictionary<TetrisColor, Bitmap> blockImages, float xOffset, float yOffset, int height)
        {
            if (_block != null)
            {
                // Define the boundaries of the block
                float left = blockSize*_block._x + xOffset;
                //float right = left + blockSize;
                float top = height == 0 ? blockSize*(Constants.GridSizeYmax - _block._y) + yOffset :
                    height - blockSize*(_block._y + 1) - yOffset;
                //float bottom = top + blockSize;

                // Draw the image inside the block
                Paint paint = new Paint();
                paint.Alpha = _isShadow ? AlphaShadow : AlphaOpaque;
                canvas.DrawBitmap(blockImages[_block._color], left, top, paint);
                paint.Dispose();
            }
        }
Esempio n. 44
0
        private static void drawPolygonInCanvas(Canvas canvas, PointF[] polygon, Color color)
        {
            var path = new Path();
            // Set the first point, that the drawing will start from.
            path.MoveTo(polygon[0].X, polygon[0].Y);
            for (var i = 1; i < polygon.Length; i++)
            {
                // Draw a line from the previous point in the path to the new point.
                path.LineTo(polygon[i].X, polygon[i].Y);
            }

            Paint paint = new Paint {
                AntiAlias = true,
                Color = color
            };
            paint.SetStyle(Paint.Style.Fill);
            canvas.DrawPath(path, paint);

            paint.Dispose();
        }
Esempio n. 45
0
        //--------------------------------------------------------------
        // STATIC METHODS
        //--------------------------------------------------------------
        public static Bitmap CreateImage(int blockSize, TetrisColor color)
        {
            if(color == TetrisColor.ColorMax)
                return null;

            // Create the image with its canvas to draw in it
            Bitmap image = Bitmap.CreateBitmap(blockSize, blockSize, Bitmap.Config.Argb8888);
            Canvas imageCanvas = new Canvas(image);

            // Calculate the width of the borders with a percentage of the size of the block
            float borderWidth = BorderWidth * blockSize;
            float borderWidth3D = BorderWidth3D * blockSize;

            // Calculate all the colors for the block based on its tetris color
            Color baseColor = adjustColor(Utils.getAndroidColor(color), SvBaseColor);
            Color topColor = adjustColor(baseColor, SvTopColor);
            Color leftColor = adjustColor(baseColor, SvLeftColor);
            Color rightColor = adjustColor(baseColor, SvRightColor);
            Color bottomColor = adjustColor(baseColor, SvBottomColor);
            Color borderColor = adjustColor(baseColor, SvBorderColor);

            // Draw the border
            Paint borderPaint = new Paint {AntiAlias = true, Color = borderColor};
            for(int i = 0 ; i < BorderWidth ; i++)
            {
                imageCanvas.DrawRect(i, blockSize - i, blockSize - i, i, borderPaint);
            }
            borderPaint.Dispose();

            // Define the corners of the big rectangle without the border
            PointF outerRectTopLeft = new PointF(
                borderWidth,
                borderWidth);
            PointF outerRectTopRight = new PointF(
                blockSize - borderWidth,
                borderWidth);
            PointF outerRectBottomRight = new PointF(
                blockSize - borderWidth,
                blockSize - borderWidth);
            PointF outerRectBottomLeft = new PointF(
                borderWidth,
                blockSize - borderWidth);

            // Define the corners of the small rectangle in the middle
            PointF innerRectTopLeft = new PointF(
                borderWidth + borderWidth3D,
                borderWidth + borderWidth3D);
            PointF innerRectTopRight = new PointF(
                blockSize -borderWidth - borderWidth3D,
                borderWidth + borderWidth3D);
            PointF innerRectBottomRight = new PointF(
                blockSize -borderWidth - borderWidth3D,
                blockSize -borderWidth - borderWidth3D);
            PointF innerRectBottomLeft = new PointF(
                borderWidth + borderWidth3D,
                blockSize -borderWidth - borderWidth3D);

            // Draw inner square
            PointF[] innerSquare = new[]
            {
                innerRectTopLeft,
                innerRectTopRight,
                innerRectBottomRight,
                innerRectBottomLeft
            };
            drawPolygonInCanvas(imageCanvas, innerSquare, baseColor);

            // Draw top 3D border
            PointF[] top3dBorder = new[]
            {
                outerRectTopLeft,
                outerRectTopRight,
                innerRectTopRight,
                innerRectTopLeft
            };
            drawPolygonInCanvas(imageCanvas, top3dBorder, topColor);

            // Draw bottom 3D border
            PointF[] bottom3dBorder = new[]
            {
                innerRectBottomLeft,
                innerRectBottomRight,
                outerRectBottomRight,
                outerRectBottomLeft
            };
            drawPolygonInCanvas(imageCanvas, bottom3dBorder, bottomColor);

            // Draw left 3D border
            PointF[] left3dBorder = new[]
            {
                outerRectTopLeft,
                innerRectTopLeft,
                innerRectBottomLeft,
                outerRectBottomLeft
            };
            drawPolygonInCanvas(imageCanvas, left3dBorder, leftColor);

            // Draw right 3D border
            PointF[] right3dBorder = new[]
            {
                innerRectTopRight,
                outerRectTopRight,
                outerRectBottomRight,
                innerRectBottomRight
            };
            drawPolygonInCanvas(imageCanvas, right3dBorder, rightColor);

            imageCanvas.Dispose();

            return image;
        }
        private void loadProfilePicture(Guid contactId)
        {
            if (contactId != null) {
                ContactDB cont = new ContactDB ();
                if (contacts.ContainsKey (contactId))
                    cont = contacts [contactId];

                byte[] imgdata = cont.ContactUser.Picture;
                Bitmap original = BitmapFactory.DecodeByteArray (imgdata, 0, imgdata.Length);
                Bitmap mask = Bitmap.CreateScaledBitmap (BitmapFactory.DecodeResource (Resources, Resource.Drawable.emptybackground), original.Width, original.Height, true);
                Bitmap result = Bitmap.CreateBitmap (mask.Width, mask.Height, Bitmap.Config.Argb8888);
                Canvas canv = new Canvas (result);
                Paint paint = new Paint (PaintFlags.AntiAlias);

                paint.SetXfermode (new PorterDuffXfermode (PorterDuff.Mode.DstIn));
                canv.DrawBitmap (original, 0, 0, null);
                canv.DrawBitmap (mask, 0, 0, paint);
                paint.SetXfermode (null);

                RunOnUiThread (delegate {
                    ImageView pic = (ImageView)converse.FindViewWithTag (new Java.Lang.String ("profilepic_" + contactId.ToString ()));
                    pic.SetImageBitmap (result);
                    original.Dispose ();
                    mask.Dispose ();
                    paint.Dispose ();
                    canv.Dispose ();
                    result.Dispose ();
                });
            }
        }
Esempio n. 47
0
        //--------------------------------------------------------------
        // PROTECTED METHODS
        //--------------------------------------------------------------
        protected bool InitializeUI()
        {
            _buttonLayout.SetMinimumHeight(Math.Max(_positiveButton.Height, _negativeButton.Height));

            // Initialize background
            if(_root.Width <= 0 || _root.Height <= 0)
                return false;

            if(_backgroundImage != null)
            {
                _backgroundImage.Recycle();
                _backgroundImage.Dispose();
            }

            _backgroundImage = Bitmap.CreateBitmap(_root.Width, _root.Height, Bitmap.Config.Argb8888);
            Canvas canvas = new Canvas(_backgroundImage);

            Rect local = new Rect();
            _root.GetLocalVisibleRect(local);
            RectF bounds = new RectF(local);
            bounds.Top += Builder.StrokeBorderWidth/2;
            bounds.Left += Builder.StrokeBorderWidth/2;
            bounds.Right -= Builder.StrokeBorderWidth/2;
            bounds.Bottom -= Builder.StrokeBorderWidth/2;

            // Background fill paint
            Paint fillBackPaint = new Paint();
            fillBackPaint.Color = Builder.FillColor;
            fillBackPaint.AntiAlias = true;

            // Background stroke paint
            Paint strokeBackPaint = new Paint();
            strokeBackPaint.Color = Builder.StrokeColor;
            strokeBackPaint.SetStyle(Paint.Style.Stroke);
            strokeBackPaint.StrokeWidth = Builder.StrokeBorderWidth;
            strokeBackPaint.AntiAlias = true;

            canvas.DrawRoundRect(bounds, Builder.RadiusOut, Builder.RadiusOut, strokeBackPaint);
            canvas.DrawRoundRect(bounds, Builder.RadiusIn, Builder.RadiusIn, fillBackPaint);

            _root.SetBackgroundDrawable(new BitmapDrawable(_backgroundImage));

            canvas.Dispose();
            strokeBackPaint.Dispose();
            fillBackPaint.Dispose();

            return true;
        }
Esempio n. 48
0
        private void setBackground()
        {
            LinearLayout player2layout = FindViewById<LinearLayout>(Resource.Id.player2layout);

            if(_player2background != null)
            {
                _player2background.Recycle();
                _player2background.Dispose();
            }
            // Create image
            _player2background = Bitmap.CreateBitmap(player2layout.Width, player2layout.Height, Bitmap.Config.Argb8888);
            Canvas backCanvas = new Canvas(_player2background);

            // Background stroke paint
            float strokeBorderWidth = (FindViewById<ButtonStroked>(Resource.Id.buttonMoveLeft)).Settings.StrokeBorderWidth;
            int padding = (int)strokeBorderWidth/2 + Utils.GetPixelsFromDP(this, 5);
            player2layout.SetPadding(padding, 0, 0, padding);

            Paint strokeBackPaint = new Paint();
            strokeBackPaint.Color = Utils.getAndroidColor(TetrisColor.Red);
            strokeBackPaint.SetStyle(Paint.Style.Stroke);
            strokeBackPaint.StrokeWidth = strokeBorderWidth/2;
            strokeBackPaint.AntiAlias = true;

            // Get rectangle
            Rect local = new Rect();
            player2layout.GetLocalVisibleRect(local);
            RectF bounds = new RectF(local);
            bounds.Left += strokeBorderWidth/2;
            bounds.Bottom -= strokeBorderWidth/2;
            bounds.Top -= strokeBorderWidth;
            bounds.Right += strokeBorderWidth;

            // Actually draw background
            int radiusIn = (FindViewById<ButtonStroked>(Resource.Id.buttonMoveLeft)).Settings.RadiusIn;
            int radiusOut = (FindViewById<ButtonStroked>(Resource.Id.buttonMoveLeft)).Settings.RadiusOut;
            backCanvas.DrawRoundRect(bounds, radiusOut, radiusOut, strokeBackPaint);

            // Use it as background
            player2layout.SetBackgroundDrawable(new BitmapDrawable(_player2background));

            backCanvas.Dispose();
            strokeBackPaint.Dispose();
        }
Esempio n. 49
-1
		public static Bitmap GetImage(int width, int height, string intensiteit)
		{
			intensity = intensiteit;
			sizeBlocks = width / 7;
			int amountImages = 56;
			List<Bitmap> bitmaps = DrawImages.CreateBitmapBlocks (amountImages,false);
			Paint p = new Paint ();
			p.StrokeWidth = 0.5f;
			p.SetStyle (Paint.Style.Fill);
			p.Color = Color.White;
			Bitmap b = Bitmap.CreateBitmap (width, height, Bitmap.Config.Argb8888);
			Canvas c = new Canvas (b);
			//Make background White
			c.DrawRect (new Rect (0, 0, width, height), p);
			//Draw Blocks
			for(int i=0;i<amountImages;i++)
			{
				c.DrawBitmap (bitmaps[i], (i % 7) * (width / 7), (i % 8) * (height / 8), p);
			}
			p.Dispose ();
			c.Dispose ();
			return b;
		}