protected override Bitmap Transform(IBitmapPool bitmapPool, Bitmap source, int outWidth, int outHeight)
		{
			int size = Math.Min(source.Width, source.Height);

			int width = (source.Width - size) / 2;
			int height = (source.Height - size) / 2;

			Bitmap squaredBitmap = Bitmap.CreateBitmap(source, width, height, size, size);
			if (squaredBitmap != source)
			{
				source.Recycle();
			}

			Bitmap bitmap = Bitmap.CreateBitmap(size, size, Bitmap.Config.Argb8888);

			Canvas canvas = new Canvas(bitmap);
			Paint paint = new Paint();
			BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.Clamp,
					BitmapShader.TileMode.Clamp);
			paint.SetShader(shader);
			paint.AntiAlias = true;

			float r = size / 2f;
			canvas.DrawCircle(r, r, r, paint);

			squaredBitmap.Recycle();

			return BitmapResource.Obtain(bitmap, bitmapPool).Get();
		}
        protected override void DispatchDraw(Canvas canvas)
        {
            int height = Height;
            int width  = Width;

            if (gradientStyle == "Vertical")
            {
                width = 0;
            }
            else
            {
                height = 0;
            }

            /*
             #region for Vertical Gradient
             * var gradient = new Android.Graphics.LinearGradient(0, 0, 0, Height,
             #endregion
             *
             * //#region for Horizontal Gradient
             * //var gradient = new Android.Graphics.LinearGradient(0, 0, Width, 0,
             *
             * this.StartColor.ToAndroid(),
             * this.EndColor.ToAndroid(),
             * Android.Graphics.Shader.TileMode.Mirror);
             * //#endregion
             */


            var gradient = new Android.Graphics.LinearGradient(0, 0, width, height, this.StartColor.ToAndroid(), this.EndColor.ToAndroid(), Android.Graphics.Shader.TileMode.Mirror);
            var paint    = new Android.Graphics.Paint()
            {
                Dither = true,
            };


            paint.SetShader(gradient);
            canvas.Save();
            canvas.ClipPath(_path);
            canvas.DrawPaint(paint);
            try
            {
                if (stack.HasBorderColor == true && stack.BorderColor != null)
                {
                    var borderPaint = new Paint();
                    borderPaint.AntiAlias   = true;
                    borderPaint.StrokeWidth = 5;
                    borderPaint.SetStyle(Paint.Style.Stroke);
                    borderPaint.Color = stack.BorderColor.ToAndroid();//global::Android.Graphics.Color.White;
                    canvas.DrawPath(_path, borderPaint);
                }
            }
            catch (Exception ex)
            {
                var msg = ex.Message;
            }
            //base.Draw(canvas);
            base.DispatchDraw(canvas);
            canvas.Restore();
        }
        public static Bitmap ToRounded(Bitmap source, float rad)
        {
            int size = Math.Min(source.Width, source.Height);

            int dx = (source.Width - size) / 2;
            int dy = (source.Height - size) / 2;

            Bitmap bitmap = Bitmap.CreateBitmap(size, size, Bitmap.Config.Argb8888);

            using (Canvas canvas = new Canvas(bitmap))
            using (Paint paint = new Paint())
            using (BitmapShader shader = new BitmapShader(source, Shader.TileMode.Clamp, Shader.TileMode.Clamp))
            using (Matrix matrix = new Matrix())
            {
                if (dx != 0 || dy != 0)
                {
                    // source isn't square, move viewport to centre
                    matrix.SetTranslate(-dx, -dy);
                    shader.SetLocalMatrix(matrix);
                }
                paint.SetShader(shader);
                paint.AntiAlias = true;

                RectF rectF = new RectF(0, 0, size, size);
                canvas.DrawRoundRect(rectF, rad, rad, paint);

                return bitmap;
            }
        }
Esempio n. 4
0
        void SetLinearGradientPaint(APaint platformPaint, LinearGradientPaint linearGradientPaint)
        {
            var p1 = linearGradientPaint.StartPoint;
            var x1 = (float)p1.X;
            var y1 = (float)p1.Y;
            var p2 = linearGradientPaint.EndPoint;
            var x2 = (float)p2.X;
            var y2 = (float)p2.Y;

            var data   = GetGradientPaintData(linearGradientPaint);
            var shader = new LinearGradientData(data.Colors, data.Offsets, x1, y1, x2, y2);

            if (_width == 0 && _height == 0)
            {
                return;
            }

            if (shader.Colors == null || shader.Colors.Length < 2)
            {
                return;
            }

            var linearGradientShader = new LinearGradient(
                _width * shader.X1,
                _height * shader.Y1,
                _width * shader.X2,
                _height * shader.Y2,
                shader.Colors,
                shader.Offsets,
                Shader.TileMode.Clamp !);

            platformPaint.SetShader(linearGradientShader);
        }
Esempio n. 5
0
        public void SetRadialGradientPaint(APaint platformPaint, RadialGradientPaint radialGradientPaint)
        {
            var   center  = radialGradientPaint.Center;
            float centerX = (float)center.X;
            float centerY = (float)center.Y;
            float radius  = (float)radialGradientPaint.Radius;

            var gradientData       = GetGradientPaintData(radialGradientPaint);
            var radialGradientData = new RadialGradientData(gradientData.Colors, gradientData.Offsets, centerX, centerY, radius);

            if (_width == 0 && _height == 0)
            {
                return;
            }

            if (radialGradientData.Colors == null || radialGradientData.Colors.Length < 2)
            {
                return;
            }

            var radialGradient = new RadialGradient(
                _width * radialGradientData.CenterX,
                _height * radialGradientData.CenterY,
                Math.Max(_height, _width) * radialGradientData.Radius,
                radialGradientData.Colors,
                radialGradientData.Offsets,
                Shader.TileMode.Clamp !);

            platformPaint.SetShader(radialGradient);
        }
        public Bitmap Transform(Bitmap source)
        {
            int size = Math.Min(source.Width, source.Height);

            int width = (source.Width - size) / 2;
            int height = (source.Height - size) / 2;

            var bitmap = Bitmap.CreateBitmap(size, size, Bitmap.Config.Argb4444);

            var canvas = new Canvas(bitmap);
            var paint = new Paint();
            var shader =
                new BitmapShader(source, BitmapShader.TileMode.Clamp, BitmapShader.TileMode.Clamp);
            if (width != 0 || height != 0)
            {
                // source isn't square, move viewport to center
                var matrix = new Matrix();
                matrix.SetTranslate(-width, -height);
                shader.SetLocalMatrix(matrix);
            }
            paint.SetShader(shader);
            paint.AntiAlias = true;

            float r = size / 2f;
            canvas.DrawCircle(r, r, r, paint);

            source.Recycle();

            return bitmap;
        }
        protected override void DispatchDraw(Canvas canvas)
        {
            LinearGradient linearGradient;

            if (IsVertical)
            {
                linearGradient = new Android.Graphics.LinearGradient(0, 0, 0, Height,
                                                                     this.StartColor.ToAndroid(),
                                                                     this.EndColor.ToAndroid(),
                                                                     Android.Graphics.Shader.TileMode.Mirror);
            }
            else
            {
                linearGradient = new Android.Graphics.LinearGradient(0, 0, 0, Width,
                                                                     this.StartColor.ToAndroid(),
                                                                     this.EndColor.ToAndroid(),
                                                                     Android.Graphics.Shader.TileMode.Mirror);
            }
            Paint paint = new Android.Graphics.Paint()
            {
                Dither = true,
            };

            paint.SetShader(linearGradient);
            canvas.DrawPaint(paint);
            base.DispatchDraw(canvas);
        }
Esempio n. 8
0
		public CircleDrawable (Bitmap bmp)
		{
			this.bmp = bmp;
			bmpShader = new BitmapShader (bmp, Shader.TileMode.Clamp, Shader.TileMode.Clamp);
			paint = new Paint { AntiAlias = true };
			paint.SetShader (bmpShader);
			oval = new RectF ();
		}
Esempio n. 9
0
        public void Refresh()
        {
            LinkedList<DView> views = myEventHandler.GetAllView();
            Canvas c = null;
            try
            {
                if (surfaceHolder.Surface.IsValid)
                {
                    c = surfaceHolder.LockCanvas();

                    lock (surfaceHolder)
                    {
                        Paint paint = new Paint();
                        Paint paintShader = new Paint();
                        paint.Color = Color.Black;
                        c.DrawRect(0, 0
                            , this.Width, this.Height, paint);
                        foreach (var view in views)
                        {
                            if(view.ViewType==DViewType.Circle)
                            {
                                Color color=new Color(view.Pattern.Color);
                                color.A=255;
                                paint.Color = color;
                                c.DrawCircle(view.X, view.Y, view.Radius, paint);
                            }else
                            {
                                if (view.Pattern.PatternType == DPatternType.Image)
                                {
                                    BitmapShader shader = new BitmapShader(view.Pattern.Image, Shader.TileMode.Repeat, Shader.TileMode.Repeat);
                                    paintShader.SetStyle(Paint.Style.Fill);
                                    paintShader.SetShader(shader);
                                    c.DrawRect(view.X - view.Radius, view.Y - view.Radius
                                        , view.X + view.Radius, view.Y + view.Radius, paintShader);

                                }else
                                {
                                    Color color = new Color(view.Pattern.Color);
                                    color.A = 255;
                                    paint.Color = color;
                                    c.DrawRect(view.X - view.Radius, view.Y - view.Radius
                                        , view.X + view.Radius, view.Y + view.Radius, paint);
                                }
                            }
                        }
                    }
                }
            }
            catch(Exception ex)
            {
                Log.Error("MySurfaceView",ex.Message);
            }
            finally
            {
                if (c != null)
                    surfaceHolder.UnlockCanvasAndPost(c);
            }
        }
Esempio n. 10
0
		public object Create(Color startColor, Color endColor, PointF startPoint, PointF endPoint)
		{
			var shader = new ag.LinearGradient(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y, startColor.ToAndroid(), endColor.ToAndroid(), 
				// is this correct?
				ag.Shader.TileMode.Clamp);
			var paint = new ag.Paint();
			paint.SetShader(shader);
			return new BrushObject { Paint = paint }; // TODO: initial matrix
		}
Esempio n. 11
0
        public void FillRectangleLinear(SolidColor startColor, SolidColor endColor, float angle, Rectangle rect)
        {
            using (var p = new Paint())
            {
                p.SetShader(new LinearGradient(rect.Left, rect.Top, rect.Left, rect.Bottom,
                                               startColor, endColor, Shader.TileMode.Mirror));

                this.canvas.DrawRect((RectF)rect, p);
            }
        }
Esempio n. 12
0
        protected override void DispatchDraw(Canvas canvas)
        {
            Android.Graphics.LinearGradient gradient = null;

            int[] colors = new int[Colors.Length];
            for (int i = 0, l = Colors.Length; i < l; i++)
            {
                colors[i] = Colors[i].ToAndroid().ToArgb();
            }

            switch (Mode)
            {
            case SupportGradientViewMode.ToRight:
                gradient = new Android.Graphics.LinearGradient(0, 0, Width, 0, colors, null, Android.Graphics.Shader.TileMode.Mirror);
                break;

            case SupportGradientViewMode.ToLeft:
                gradient = new Android.Graphics.LinearGradient(Width, 0, 0, 0, colors, null, Android.Graphics.Shader.TileMode.Mirror);
                break;

            case SupportGradientViewMode.ToTop:
                gradient = new Android.Graphics.LinearGradient(0, Height, 0, 0, colors, null, Android.Graphics.Shader.TileMode.Mirror);
                break;

            case SupportGradientViewMode.ToBottom:
                gradient = new Android.Graphics.LinearGradient(0, 0, 0, Height, colors, null, Android.Graphics.Shader.TileMode.Mirror);
                break;

            case SupportGradientViewMode.ToTopLeft:
                gradient = new Android.Graphics.LinearGradient(Width, Height, 0, 0, colors, null, Android.Graphics.Shader.TileMode.Mirror);
                break;

            case SupportGradientViewMode.ToTopRight:
                gradient = new Android.Graphics.LinearGradient(0, Height, Width, 0, colors, null, Android.Graphics.Shader.TileMode.Mirror);
                break;

            case SupportGradientViewMode.ToBottomLeft:
                gradient = new Android.Graphics.LinearGradient(Width, 0, 0, Height, colors, null, Android.Graphics.Shader.TileMode.Mirror);
                break;

            case SupportGradientViewMode.ToBottomRight:
                gradient = new Android.Graphics.LinearGradient(0, 0, Width, Height, colors, null, Android.Graphics.Shader.TileMode.Mirror);
                break;
            }

            var paint = new Android.Graphics.Paint()
            {
                Dither = true,
            };

            paint.SetShader(gradient);
            canvas.DrawPaint(paint);

            base.DispatchDraw(canvas);
        }
Esempio n. 13
0
        public object Create(Color startColor, Color endColor, PointF startPoint, PointF endPoint)
        {
            var shader = new ag.LinearGradient(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y, startColor.ToAndroid(), endColor.ToAndroid(),
                                               // is this correct?
                                               ag.Shader.TileMode.Clamp);
            var paint = new ag.Paint();

            paint.SetShader(shader);
            return(new BrushObject {
                Paint = paint
            });                                                   // TODO: initial matrix
        }
 public OvalShadow(int shadowRadius, int circleDiameter, CircleProgressBar progressBar)
     : base()
 {
     mProgressBar = progressBar;
     mShadowPaint = new Paint();
     mShadowRadius = shadowRadius;
     mCircleDiameter = circleDiameter;
     mRadialGradient = new RadialGradient(mCircleDiameter / 2, mCircleDiameter / 2,
         mShadowRadius, new int[] { FILL_SHADOW_COLOR, Color.Transparent },
         null, Shader.TileMode.Clamp);
     mShadowPaint.SetShader(mRadialGradient);
 }
Esempio n. 15
0
        public VignetteDrawable(Bitmap bitmap, float cornerRadius = 5, int margin = 3, bool withEffect = true)
        {
            useGradientOverlay = withEffect;
            mCornerRadius = cornerRadius;

            bitmapShader = new BitmapShader (bitmap, Shader.TileMode.Clamp, Shader.TileMode.Clamp);

            paint = new Paint () { AntiAlias = true };
            paint.SetShader (bitmapShader);

            margin = margin;
        }
Esempio n. 16
0
		private void Init()
		{
			Drawable drawable = this.Drawable;
			bitmap = Bitmap.CreateScaledBitmap (((BitmapDrawable)drawable).Bitmap, this.Width, this.Height, false);

			BitmapShader shader;
			shader = new BitmapShader (bitmap, Shader.TileMode.Clamp, Shader.TileMode.Clamp);

			// init paint
			paint = new Paint ();
			paint.AntiAlias = true;
			paint.SetShader (shader);
		}
        public RoundedImage(Bitmap bitmap)
        {
            mBitmap = bitmap;
            mRectF = new RectF();
            mPaint = new Paint();
            mPaint.AntiAlias = true;
            mPaint.Dither = true;
            BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.Clamp, Shader.TileMode.Clamp);
            mPaint.SetShader(shader);

            // NOTE: we assume bitmap is properly scaled to current density
            mBitmapWidth = mBitmap.Width;
            mBitmapHeight = mBitmap.Height;
        }
        protected override void DispatchDraw(
            global::Android.Graphics.Canvas canvas)
        {
//            var gradient = new Android.Graphics.LinearGradient(0, 0, Width, 0, 
//                               this.StartColor.ToAndroid(),
//                               this.EndColor.ToAndroid(),
//                               Android.Graphics.Shader.TileMode.Mirror);
            var gradient = new RadialGradient(-100, 1200, 3000, this.StartColor.ToAndroid(), this.EndColor.ToAndroid(), Android.Graphics.Shader.TileMode.Clamp);//(-50, -50, this.StartColor.ToAndroid(), this.EndColor.ToAndroid());
            var paint = new Android.Graphics.Paint() {
                Dither = true,
            };
            paint.SetShader(gradient);
            canvas.DrawPaint(paint);
            base.DispatchDraw(canvas);
        }
Esempio n. 19
0
        public RoundedDrawable(Bitmap bitmap) : base()
        {
            mBitmap = bitmap;
            mRectF = new RectF();
            mPaint = new Paint();
            mPaint.AntiAlias = true;
            mPaint.Dither = true;

            BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.Clamp, Shader.TileMode.Clamp);
            mPaint.SetShader(shader);

            // Try to get it circular, even if the given bitmap isn't square
            mBitmapWidth = Math.Min( mBitmap.Width, mBitmap.Height);
            mBitmapHeight = Math.Min(mBitmap.Width, mBitmap.Height);
        }
			protected override void OnDraw (Canvas canvas)
			{
				canvas.DrawColor (Color.White);

				Paint p = new Paint ();
				float y = 10;

				p.Color = Color.Red;
				canvas.DrawBitmap (mBitmap, 10, y, p);
				y += mBitmap.Height + 10;
				canvas.DrawBitmap (mBitmap2, 10, y, p);
				y += mBitmap2.Height + 10;
				p.SetShader (mShader);
				canvas.DrawBitmap (mBitmap3, 10, y, p);
			}
        protected override void DispatchDraw(Canvas canvas)
        {
            var gradient = new Android.Graphics.LinearGradient(0, 0, Width, 0,
                                                               this.StartColor.ToAndroid(),
                                                               this.EndColor.ToAndroid(),
                                                               Android.Graphics.Shader.TileMode.Mirror);

            var paint = new Android.Graphics.Paint()
            {
                Dither = true
            };

            paint.SetShader(gradient);
            canvas.DrawPaint(paint);
            base.DispatchDraw(canvas);
        }
Esempio n. 22
0
        void OnElementSizeChanged(object sender, EventArgs e)
        {
            var elem = sender as View;
            if (elem == null)
                return;
            using (var imageBitmap = Bitmap.CreateBitmap((int)elem.Width, (int)elem.Height, Bitmap.Config.Argb8888))
            using (var canvas = new Canvas(imageBitmap))
            using (var gradient = new RadialGradient(0, 250, 1000, currentElement.StartColor.ToAndroid(), currentElement.EndColor.ToAndroid(), Shader.TileMode.Clamp))
            using (var paint = new Paint() { Dither = true })
            {
                paint.SetShader(gradient);
                canvas.DrawPaint(paint);

                Container.Background = new BitmapDrawable(imageBitmap);
            }
        }
        protected override Bitmap Transform(Bitmap source)
        {
            int width = source.Width;
            int height = source.Height;

            Bitmap bitmap = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888);

            Canvas canvas = new Canvas(bitmap);
            Paint paint = new Paint();
            paint.AntiAlias = true;
            paint.SetShader(new BitmapShader(source, Shader.TileMode.Clamp, Shader.TileMode.Clamp));
            canvas.DrawRoundRect(new RectF(margin, margin, width - margin, height - margin), radius, radius, paint);
            source.Recycle();

            return bitmap;
        }
        protected override void DispatchDraw(Canvas canvas)
        {
            var gradient = new Android.Graphics.LinearGradient(
                0, 0, Width, Height,
                new int[] { _startColor.ToAndroid(), _middleColor.ToAndroid(), _endColor.ToAndroid() },
                null,
                Android.Graphics.Shader.TileMode.Mirror);
            var paint = new Android.Graphics.Paint()
            {
                Dither = true,
            };

            paint.SetShader(gradient);
            canvas.DrawPaint(paint);
            base.DispatchDraw(canvas);
        }
        public override void Draw(Canvas canvas)
        {
            base.Draw(canvas);
            var gradient = new Android.Graphics.LinearGradient(0, Height, 0, 0,
                                                               this.StartColor.ToAndroid(), this.EndColor.ToAndroid(), Android.Graphics.Shader.TileMode.Mirror);

            var paint = new Android.Graphics.Paint()
            {
                Dither    = true,
                AntiAlias = true
            };

            paint.SetShader(gradient);
            var rect = new RectF(0, 0, Width, Height);

            canvas.DrawRect(rect, paint);
        }
Esempio n. 26
0
 protected override void OnDraw(Canvas canvas)
 {
     if (Control != null && Element is CustomFrame frame)
     {
         var paint = new Android.Graphics.Paint()
         {
             Dither = true,
         };
         if (Gradient != null)
         {
             paint.SetShader(Gradient);
         }
         var path = RoundedRect(0, 0, Width, Height, Context.ToPixels(frame.CornerRadius.TopRight), Context.ToPixels(frame.CornerRadius.TopLeft), true);
         canvas.DrawPath(path, paint);
     }
     base.OnDraw(canvas);
 }
Esempio n. 27
0
 protected override void DispatchDraw(Canvas canvas)
 {
     #region for Vertical Gradient
     var gradient = new Android.Graphics.LinearGradient(0, 0, 0, Height,
                                                        #endregion
                                                        //var gradient = new Android.Graphics.LinearGradient(0, 0, Width, Height,
                                                        this.StartColor.ToAndroid(),
                                                        this.EndColor.ToAndroid(),
                                                        Android.Graphics.Shader.TileMode.Clamp);
     var paint = new Android.Graphics.Paint()
     {
         Dither = true,
     };
     paint.SetShader(gradient);
     canvas.DrawPaint(paint);
     base.DispatchDraw(canvas);
 }
        protected override void DispatchDraw(global::Android.Graphics.Canvas canvas)

        {
            #region for Horizontal Gradient

            LinearGradient gradient = new Android.Graphics.LinearGradient(0, 0, Width, 0,

                                                                          #endregion



                                                                          StartColor.ToAndroid(),

                                                                          EndColor.ToAndroid(),

                                                                          Android.Graphics.Shader.TileMode.Mirror);



            Paint paint = new Android.Graphics.Paint()

            {
                Dither = true,
            };

            float rx = _context.ToPixels(_cornerRadius);

            float ry = _context.ToPixels(_cornerRadius);

            RectF rect = new RectF(0, 0, Width, Height);

            Path path = new Path();

            path.AddRoundRect(rect, rx, ry, Path.Direction.Cw);



            paint.StrokeWidth = 5f;  //set outline stroke

            paint.SetShader(gradient);

            canvas.DrawPath(path, paint);

            base.DispatchDraw(canvas);
        }
Esempio n. 29
0
        public RoundCornerDrawable(Bitmap bitmap, float cornerRadius = 5, int margin = 3)
        {
            mCornerRadius = cornerRadius;

            bitmapShader = new BitmapShader (bitmap, Shader.TileMode.Clamp, Shader.TileMode.Clamp);

            paint = new Paint () {
                AntiAlias = true,
            };
            paint.SetShader (bitmapShader);
            strokePaint = new Paint () {
                Color = Color.Rgb (200, 200, 200),
                StrokeWidth = 2,
            };
            strokePaint.SetStyle (Paint.Style.Stroke);

            this.margin = margin;
        }
Esempio n. 30
0
        public static Bitmap ToRounded(Bitmap source, float rad, double cropWidthRatio, double cropHeightRatio)
        {
            double sourceWidth = source.Width;
            double sourceHeight = source.Height;

            double desiredWidth = sourceWidth;
            double desiredHeight = sourceHeight;

            double desiredRatio = cropWidthRatio / cropHeightRatio;
            double currentRatio = sourceWidth / sourceHeight;

            if (currentRatio > desiredRatio)
                desiredWidth = (cropWidthRatio * sourceHeight / cropHeightRatio);
            else if (currentRatio < desiredRatio)
                desiredHeight = (cropHeightRatio * sourceWidth / cropWidthRatio);

            float cropX = (float)((sourceWidth - desiredWidth) / 2);
            float cropY = (float)((sourceHeight - desiredHeight) / 2);

            if (rad == 0)
                rad = (float)(Math.Min(desiredWidth, desiredHeight) / 2);

            Bitmap bitmap = Bitmap.CreateBitmap((int)desiredWidth, (int)desiredHeight, Bitmap.Config.Argb8888);

            using (Canvas canvas = new Canvas(bitmap))
            using (Paint paint = new Paint())
            using (BitmapShader shader = new BitmapShader(source, Shader.TileMode.Clamp, Shader.TileMode.Clamp))
            using (Matrix matrix = new Matrix())
            {
                if (cropX != 0 || cropY != 0)
                {
                    matrix.SetTranslate(-cropX, -cropY);
                    shader.SetLocalMatrix(matrix);
                }

                paint.SetShader(shader);
                paint.AntiAlias = true;

                RectF rectF = new RectF(0, 0, (int)desiredWidth, (int)desiredHeight);
                canvas.DrawRoundRect(rectF, rad, rad, paint);

                return bitmap;
            }
        }
Esempio n. 31
0
        static CategoryBadge()
        {
            center = OverallSize / 2;
            mainCenter = center + offset;

            backPaint = new Paint () {
                Color = Color.Rgb (0xc7, 0xc7, 0xc7),
                AntiAlias = true
            };
            backPaint.SetShader (new LinearGradient (mainCenter, 0, mainCenter, radius * 2,
                                                     Color.Rgb (0xc7, 0xc7, 0xc7),
                                                     Color.Argb (0xa2, 0xc7, 0xc70, 0xc7),
                                                     //Color.Argb (0xa2, 0xc7, 0xc7, 0xc7),
                                                     Shader.TileMode.Clamp));
            darkerBackPaint = new Paint () {
                Color = Color.Rgb (0xa7, 0xa7, 0xa7),
                AntiAlias = true
            };
            shadowPaint = new Paint () {
                Color = Color.Rgb (0x9a, 0x9a, 0x9a),
                AntiAlias = true
            };
            removePaint = new Paint () {
                AntiAlias = true,
                Color = Color.White,
                TextAlign = Paint.Align.Center,
                TextSize = 14.ToPixels ()
            };
            //removePaint.SetXfermode (new PorterDuffXfermode (PorterDuff.Mode.Clear));
            removePaint.SetXfermode (new PorterDuffXfermode (PorterDuff.Mode.DstIn));
            redPaint = new Paint () {
                Color = Color.Rgb (0xff, 0x44, 0x44),
                AntiAlias = true
            };
            greenPaint = new Paint () {
                Color = Color.Rgb (0x99, 0xcc, 0x00),
                AntiAlias = true
            };
            imgPaint = new Paint () {
                AntiAlias = false,
                FilterBitmap = false
            };
        }
		public VignetteDrawable (Bitmap bitmap, float cornerRadius = 5, int margin = 3, bool withEffect = true)
		{
			useGradientOverlay = withEffect;
			mCornerRadius = cornerRadius;

			bitmapShader = new BitmapShader (bitmap, Shader.TileMode.Clamp, Shader.TileMode.Clamp);

			paint = new Paint () {
				AntiAlias = true,
			};
			paint.SetShader (bitmapShader);
			strokePaint = new Paint () {
				Color = Color.Rgb (200, 200, 200),
				StrokeWidth = 2,
			};
			strokePaint.SetStyle (Paint.Style.FillAndStroke);

			this.margin = margin;
		}
        public RoundedDrawable(Bitmap bitmap)
        {
            _mBitmapWidth = bitmap.Width;
            _mBitmapHeight = bitmap.Height;
            _mBitmapRect.Set(0, 0, _mBitmapWidth, _mBitmapHeight);

            _mBitmapShader = new BitmapShader(bitmap, Shader.TileMode.Clamp, Shader.TileMode.Clamp);
            _mBitmapShader.SetLocalMatrix(_mShaderMatrix);

            _mBitmapPaint = new Paint();
            _mBitmapPaint.SetStyle(Paint.Style.Fill);
            _mBitmapPaint.AntiAlias = (true);
            _mBitmapPaint.SetShader(_mBitmapShader);

            _mBorderPaint = new Paint();
            _mBorderPaint.SetStyle(Paint.Style.Stroke);
            _mBorderPaint.AntiAlias = (true);
            _mBorderPaint.Color = Color.Black;
            _mBorderPaint.StrokeWidth = (_mBorderWidth);
        }
Esempio n. 34
0
        protected override void DispatchDraw(Canvas canvas)
        {
            base.DispatchDraw(canvas);
            LinearGradient gradient = null;

            //for horizontal gradient
            if (((GradientFrame)Element).GradientColorOrientation == GradientFrame.GradientOrientation.Horizontal)
            {
                gradient = new Android.Graphics.LinearGradient(0, 0, Width, 0,



                     ((GradientFrame)Element).StartColor.ToAndroid(),
                     ((GradientFrame)Element).EndColor.ToAndroid(),

                     Android.Graphics.Shader.TileMode.Mirror);

            }
            //for vertical gradient
            if (((GradientFrame)Element).GradientColorOrientation == GradientFrame.GradientOrientation.Vertical)
            {
                gradient = new Android.Graphics.LinearGradient(0, 0, 0, Height,



                     ((GradientFrame)Element).StartColor.ToAndroid(),
                     ((GradientFrame)Element).EndColor.ToAndroid(),

                     Android.Graphics.Shader.TileMode.Mirror);

            }

            var paint = new Android.Graphics.Paint()
            {
                Dither = true,
            };
            paint.SetShader(gradient);
            canvas.DrawPaint(paint);
            base.DispatchDraw(canvas);
        }
        public RoundColorPickerView(Context c, Color color)
            : base(c)
        {
            _colors = new[] {
                new Color(255,0,0,255).ToArgb(), new Color(255,0,255,255).ToArgb(), new Color(0,0,255,255).ToArgb(),
                new Color(0,255,255,255).ToArgb(), new Color(0,255,0,255).ToArgb(), new Color(255,255,0,255).ToArgb(),
                new Color(255,0,0,255).ToArgb()
            };
            using (Shader s = new SweepGradient(0, 0, _colors, null))
            {
                _paint = new Paint(PaintFlags.AntiAlias);
                _paint.SetShader(s);
                _paint.SetStyle(Paint.Style.Stroke);
                _paint.StrokeWidth = 32;
            }

            _centerPaint = new Paint(PaintFlags.AntiAlias)
                            {
                                Color = color,
                                StrokeWidth = 5
                            };
        }
Esempio n. 36
0
		public static Bitmap ToCropped(Bitmap source, double zoomFactor, double xOffset, double yOffset, double cropWidthRatio, double cropHeightRatio)
		{
			double sourceWidth = source.Width;
			double sourceHeight = source.Height;

			double desiredWidth = sourceWidth;
			double desiredHeight = sourceHeight;

			double desiredRatio = cropWidthRatio / cropHeightRatio;
			double currentRatio = sourceWidth / sourceHeight;

			if (currentRatio > desiredRatio)
				desiredWidth = (cropWidthRatio * sourceHeight / cropHeightRatio);
			else if (currentRatio < desiredRatio)
				desiredHeight = (cropHeightRatio * sourceWidth / cropWidthRatio);

			desiredWidth = zoomFactor * desiredWidth;
			desiredHeight = zoomFactor * desiredHeight;

			float cropX = (float)(((sourceWidth - desiredWidth) / 2) + xOffset);
			float cropY = (float)(((sourceHeight - desiredHeight) / 2) + yOffset);

			Bitmap bitmap = Bitmap.CreateBitmap((int)desiredWidth, (int)desiredHeight, Bitmap.Config.Argb8888);

			using (Canvas canvas = new Canvas(bitmap))
			using (Paint paint = new Paint())
			using (BitmapShader shader = new BitmapShader(source, Shader.TileMode.Clamp, Shader.TileMode.Clamp))
			using (Matrix matrix = new Matrix())
			{
				matrix.SetTranslate(-cropX, -cropY);
				shader.SetLocalMatrix(matrix);

				paint.SetShader(shader);
				paint.AntiAlias = true;

				return bitmap;				
			}
		}
Esempio n. 37
0
        protected override void OnDraw(Canvas canvas)
        {
            int mBorderWidth;
            int mCanvasSize;
            Bitmap mImage;
            Paint mPaint;
            Paint mPaintBorder;

            mPaint = new Paint();
            mPaint.AntiAlias = true;
            mPaintBorder = new Paint();
            mPaintBorder.Color = BorderColor;
            mPaint.AntiAlias = true;
            mImage = DrawableToBitmap(Drawable);
            mBorderWidth = 2;

            if (mImage != null)
            {
                mCanvasSize = canvas.Width;

                if (canvas.Height < mCanvasSize)
                {
                    mCanvasSize = canvas.Height;
                }

                Bitmap scaledBitmap = Bitmap.CreateScaledBitmap(mImage, mCanvasSize, mCanvasSize, true); //true --> apply the given scaleType.
                BitmapShader shader = new BitmapShader(scaledBitmap, Shader.TileMode.Clamp, Shader.TileMode.Clamp);
                mPaint.SetShader(shader);

                int circleCenter = (mCanvasSize - (mBorderWidth * 2)) / 2;

                if (ImageBorderVisibility)
                    canvas.DrawCircle(circleCenter + mBorderWidth, circleCenter + mBorderWidth, ((mCanvasSize - (mBorderWidth * 2)) / 2) + mBorderWidth - 4.0f, mPaintBorder);

                canvas.DrawCircle(circleCenter + mBorderWidth, circleCenter + mBorderWidth, ((mCanvasSize - (mBorderWidth * 2)) / 2) - 4.0f, mPaint);
            }
        }
Esempio n. 38
0
        public Bitmap Transform(Bitmap source)
        {
            Bitmap result = Bitmap.CreateBitmap(source.Width, source.Height, source.GetConfig());
            Bitmap noise;
            try
            {
                noise = picasso.Load(Resource.Drawable.noise).Get();
            }
            catch (Exception)
            {
                throw new Exception("Failed to apply transformation! Missing resource.");
            }

            BitmapShader shader = new BitmapShader(noise, Shader.TileMode.Repeat, Shader.TileMode.Repeat);

            ColorMatrix colorMatrix = new ColorMatrix();
            colorMatrix.SetSaturation(0);
            ColorMatrixColorFilter filter = new ColorMatrixColorFilter(colorMatrix);

            Paint paint = new Paint(PaintFlags.AntiAlias);
            paint.SetColorFilter(filter);

            Canvas canvas = new Canvas(result);
            canvas.DrawBitmap(source, 0, 0, paint);

            paint.SetColorFilter(null);
            paint.SetShader(shader);
            paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.Multiply));

            canvas.DrawRect(0, 0, canvas.Width, canvas.Height, paint);

            source.Recycle();
            noise.Recycle();

            return result;
        }
		public static Bitmap ToRounded(Bitmap source, float rad, double cropWidthRatio, double cropHeightRatio, double borderSize, string borderHexColor)
		{
			double sourceWidth = source.Width;
			double sourceHeight = source.Height;

			double desiredWidth = sourceWidth;
			double desiredHeight = sourceHeight;

			double desiredRatio = cropWidthRatio / cropHeightRatio;
			double currentRatio = sourceWidth / sourceHeight;

			if (currentRatio > desiredRatio)
				desiredWidth = (cropWidthRatio * sourceHeight / cropHeightRatio);
			else if (currentRatio < desiredRatio)
				desiredHeight = (cropHeightRatio * sourceWidth / cropWidthRatio);

			float cropX = (float)((sourceWidth - desiredWidth) / 2d);
			float cropY = (float)((sourceHeight - desiredHeight) / 2d);

			if (rad == 0)
				rad = (float)(Math.Min(desiredWidth, desiredHeight) / 2d);
			else
				rad = (float)(rad * (desiredWidth + desiredHeight) / 2d / 500d);

			Bitmap bitmap = Bitmap.CreateBitmap((int)desiredWidth, (int)desiredHeight, Bitmap.Config.Argb8888);

			using (Canvas canvas = new Canvas(bitmap))
			using (Paint paint = new Paint())
			using (BitmapShader shader = new BitmapShader(source, Shader.TileMode.Clamp, Shader.TileMode.Clamp))
			using (Matrix matrix = new Matrix())
			{
				if (cropX != 0 || cropY != 0)
				{
					matrix.SetTranslate(-cropX, -cropY);
					shader.SetLocalMatrix(matrix);
				}

				paint.SetShader(shader);
				paint.AntiAlias = true;

				RectF rectF = new RectF(0f, 0f, (float)desiredWidth, (float)desiredHeight);
				canvas.DrawRoundRect(rectF, rad, rad, paint);

				if (borderSize > 0d) 
				{
					borderSize = (borderSize * (desiredWidth + desiredHeight) / 2d / 500d);
					paint.Color = borderHexColor.ToColor(); ;
					paint.SetStyle(Paint.Style.Stroke);
					paint.StrokeWidth = (float)borderSize;
					paint.SetShader(null);

					RectF borderRectF = new RectF((float)(0d + borderSize/2d), (float)(0d + borderSize/2d), 
						(float)(desiredWidth - borderSize/2d), (float)(desiredHeight - borderSize/2d));

					canvas.DrawRoundRect(borderRectF, rad, rad, paint);
				}

				return bitmap;				
			}
		}
Esempio n. 40
0
        void DrawShadow(Canvas canvas)
        {
            if (_shadowCanvas == null)
            {
                _shadowCanvas = new Canvas();
            }

            if (_shadowPaint == null)
            {
                _shadowPaint = new Android.Graphics.Paint
                {
                    AntiAlias    = true,
                    Dither       = true,
                    FilterBitmap = true
                }
            }
            ;

            Graphics.Color solidColor = null;

            // If need to redraw shadow
            if (_invalidateShadow)
            {
                var viewHeight = _viewBounds.Height();
                var viewWidth  = _viewBounds.Width();

                if (GetChildAt(0) is AView child)
                {
                    if (viewHeight == 0)
                    {
                        viewHeight = child.MeasuredHeight;
                    }

                    if (viewWidth == 0)
                    {
                        viewWidth = child.MeasuredWidth;
                    }
                }

                // If bounds is zero
                if (viewHeight != 0 && viewWidth != 0)
                {
                    var bitmapHeight = viewHeight + MaximumRadius;
                    var bitmapWidth  = viewWidth + MaximumRadius;

                    // Reset bitmap to bounds
                    _shadowBitmap = Bitmap.CreateBitmap(
                        bitmapWidth, bitmapHeight, Bitmap.Config.Argb8888
                        );

                    // Reset Canvas
                    _shadowCanvas.SetBitmap(_shadowBitmap);

                    _invalidateShadow = false;

                    // Create the local copy of all content to draw bitmap as a
                    // bottom layer of natural canvas.
                    base.DispatchDraw(_shadowCanvas);

                    // Get the alpha bounds of bitmap
                    Bitmap extractAlpha = _shadowBitmap.ExtractAlpha();

                    // Clear past content content to draw shadow
                    _shadowCanvas.DrawColor(Android.Graphics.Color.Black, PorterDuff.Mode.Clear);

                    var shadowOpacity = (float)Shadow.Opacity;

                    if (Shadow.Paint is LinearGradientPaint linearGradientPaint)
                    {
                        var linearGradientShaderFactory = PaintExtensions.GetLinearGradientShaderFactory(linearGradientPaint, shadowOpacity);
                        _shadowPaint.SetShader(linearGradientShaderFactory.Resize(bitmapWidth, bitmapHeight));
                    }
                    if (Shadow.Paint is RadialGradientPaint radialGradientPaint)
                    {
                        var radialGradientShaderFactory = PaintExtensions.GetRadialGradientShaderFactory(radialGradientPaint, shadowOpacity);
                        _shadowPaint.SetShader(radialGradientShaderFactory.Resize(bitmapWidth, bitmapHeight));
                    }
                    if (Shadow.Paint is SolidPaint solidPaint)
                    {
                        solidColor = solidPaint.ToColor();
#pragma warning disable CA1416 // https://github.com/xamarin/xamarin-android/issues/6962
                        _shadowPaint.Color = solidColor.WithAlpha(shadowOpacity).ToPlatform();
#pragma warning restore CA1416
                    }

                    // Apply the shadow radius
                    var radius = Shadow.Radius;

                    if (radius <= 0)
                    {
                        radius = 0.01f;
                    }

                    if (radius > 100)
                    {
                        radius = MaximumRadius;
                    }

                    _shadowPaint.SetMaskFilter(new BlurMaskFilter(radius, BlurMaskFilter.Blur.Normal));

                    float shadowOffsetX = (float)Shadow.Offset.X;
                    float shadowOffsetY = (float)Shadow.Offset.Y;

                    if (Clip == null)
                    {
                        _shadowCanvas.DrawBitmap(extractAlpha, shadowOffsetX, shadowOffsetY, _shadowPaint);
                    }
                    else
                    {
                        var bounds = new Graphics.RectF(0, 0, canvas.Width, canvas.Height);
                        var path   = Clip.PathForBounds(bounds)?.AsAndroidPath();

                        path.Offset(shadowOffsetX, shadowOffsetY);

                        _shadowCanvas.DrawPath(path, _shadowPaint);
                    }

                    // Recycle and clear extracted alpha
                    extractAlpha.Recycle();
                }
                else
                {
                    // Create placeholder bitmap when size is zero and wait until new size coming up
                    _shadowBitmap = Bitmap.CreateBitmap(1, 1, Bitmap.Config.Rgb565 !);
                }
            }

            // Reset alpha to draw child with full alpha
            if (solidColor != null)
#pragma warning disable CA1416 // https://github.com/xamarin/xamarin-android/issues/6962
            {
                _shadowPaint.Color = solidColor.ToPlatform();
            }
#pragma warning restore CA1416

            // Draw shadow bitmap
            if (_shadowCanvas != null && _shadowBitmap != null && !_shadowBitmap.IsRecycled)
            {
                canvas.DrawBitmap(_shadowBitmap, 0.0F, 0.0F, _shadowPaint);
            }
        }

        void ClearShadowResources()
        {
            _shadowCanvas?.Dispose();
            _shadowPaint?.Dispose();
            _shadowBitmap?.Dispose();
            _shadowCanvas = null;
            _shadowPaint  = null;
            _shadowBitmap = null;
        }
    }
Esempio n. 41
0
        private void AddBrushPaint(Paint paint, BaseBrush brush, Rect frame)
        {
            paint.SetStyle(Paint.Style.Fill);

              var sb = brush as SolidBrush;

              if (sb != null)
              {
            paint.SetARGB(sb.Color.A, sb.Color.R, sb.Color.G, sb.Color.B);
            return;
              }

              var lgb = brush as LinearGradientBrush;
              if (lgb != null)
              {
            var n = lgb.Stops.Count;
            if (n >= 2)
            {
              var locs = new float[n];
              var comps = new int[n];
              for (var i = 0; i < n; i++)
              {
            var s = lgb.Stops[i];
            locs[i] = (float) s.Offset;
            comps[i] = s.Color.Argb;
              }
              var p1 = lgb.Absolute ? lgb.Start : frame.Position + lgb.Start*frame.Size;
              var p2 = lgb.Absolute ? lgb.End : frame.Position + lgb.End*frame.Size;
              var lg = new LinearGradient(
            (float) p1.X, (float) p1.Y,
            (float) p2.X, (float) p2.Y,
            comps,
            locs,
            Shader.TileMode.Clamp);
              paint.SetShader(lg);
            }
            return;
              }

              var rgb = brush as RadialGradientBrush;
              if (rgb != null)
              {
            var n = rgb.Stops.Count;
            if (n >= 2)
            {
              var locs = new float[n];
              var comps = new int[n];
              for (var i = 0; i < n; i++)
              {
            var s = rgb.Stops[i];
            locs[i] = (float) s.Offset;
            comps[i] = s.Color.Argb;
              }
              var p1 = rgb.GetAbsoluteCenter(frame);
              var r = rgb.GetAbsoluteRadius(frame);
              var rg = new RadialGradient(
            (float) p1.X, (float) p1.Y,
            (float) r.Max,
            comps,
            locs,
            Shader.TileMode.Clamp);

              paint.SetShader(rg);
            }
            return;
              }

              throw new NotSupportedException("Brush " + brush);
        }
Esempio n. 42
0
        public static void UpdateBackground(this Paint paint, Brush brush, int height, int width)
        {
            if (paint == null || brush == null || brush.IsEmpty)
            {
                return;
            }

            if (brush is SolidColorBrush solidColorBrush)
            {
                var backgroundColor = solidColorBrush.Color;
                paint.Color = backgroundColor.ToAndroid();
            }

            if (brush is LinearGradientBrush linearGradientBrush)
            {
                var p1 = linearGradientBrush.StartPoint;
                var x1 = (float)p1.X;
                var y1 = (float)p1.Y;

                var p2 = linearGradientBrush.EndPoint;
                var x2 = (float)p2.X;
                var y2 = (float)p2.Y;

                var gradientBrushData = linearGradientBrush.GetGradientBrushData();
                var colors            = gradientBrushData.Item1;
                var offsets           = gradientBrushData.Item2;

                if (colors.Length < 2)
                {
                    return;
                }

                var linearGradientShader = new LinearGradient(
                    width * x1,
                    height * y1,
                    width * x2,
                    height * y2,
                    colors,
                    offsets,
                    Shader.TileMode.Clamp);

                paint.SetShader(linearGradientShader);
            }

            if (brush is RadialGradientBrush radialGradientBrush)
            {
                var   center  = radialGradientBrush.Center;
                float centerX = (float)center.X;
                float centerY = (float)center.Y;
                float radius  = (float)radialGradientBrush.Radius;

                var gradientBrushData = radialGradientBrush.GetGradientBrushData();
                var colors            = gradientBrushData.Item1;
                var offsets           = gradientBrushData.Item2;

                if (colors.Length < 2)
                {
                    return;
                }

                var radialGradientShader = new RadialGradient(
                    width * centerX,
                    height * centerY,
                    Math.Max(height, width) * radius,
                    colors,
                    offsets,
                    Shader.TileMode.Clamp);

                paint.SetShader(radialGradientShader);
            }
        }
        private void CustomDispatchDraw(Canvas canvas)
        {
            try
            {
                this.StartColor    = stack.StartColor;
                this.EndColor      = stack.EndColor;
                this.gradientStyle = stack.GradientDirection;
                if (_path != null)
                {
                    int height = Height;
                    int width  = Width;

                    if (gradientStyle == GradientStyle.Vertical)
                    {
                        width = 0;
                    }
                    else if (gradientStyle == GradientStyle.Horizontal)
                    {
                        height = 0;
                    }
                    else
                    {
                        height = 0;
                    }

                    var gradient = new Android.Graphics.LinearGradient(0, 0, width, height, this.StartColor.ToAndroid(), this.EndColor.ToAndroid(), Android.Graphics.Shader.TileMode.Mirror);
                    var paint    = new Android.Graphics.Paint()
                    {
                        Dither = true,
                    };

                    paint.SetShader(gradient);
                    canvas.Save();
                    canvas.ClipPath(_path);
                    canvas.DrawPaint(paint);
                    try
                    {
                        if (stack.HasBorderColor == true)
                        {
                            var borderPaint = new Paint();
                            borderPaint.AntiAlias   = true;
                            borderPaint.StrokeWidth = 2;
                            borderPaint.SetStyle(Paint.Style.Stroke);
                            borderPaint.Color = stack.BorderColor.ToAndroid();//global::Android.Graphics.Color.White;
                            canvas.DrawPath(_path, borderPaint);
                        }
                    }
                    catch (Exception ex)
                    {
                        var msg = ex.Message + "\n" + ex.StackTrace;
                        System.Diagnostics.Debug.WriteLine(msg);
                    }
                    canvas.Restore();
                }
            }
            catch (Exception ex)
            {
                var msg = ex.Message + "\n" + ex.StackTrace;
                System.Diagnostics.Debug.WriteLine(msg);
            }
        }
        protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime)
        {
            var box = (GradientContentView)Element;
            //var radius = Math.Min(box.Width, Height) / 2;
            //var strokeWidth = 10;
            //radius -= strokeWidth / 2;

            ////Create path to clip
            //var path = new Path();
            //path.AddRoundRect(0,0,0,0, (float)box.Width, (float)box.Height, Path.Direction.Ccw);
            //canvas.Save();
            //canvas.ClipPath(path);

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

            //canvas.Restore();

            //canvas.S
            //// 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.ParseColor(((ImageCircle)Element).BorderColor);

            //canvas.DrawPath(path, paint);

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

            //var path = new RoundRectShape(new float[] { 8, 8, 8, 8, 8, 8, 8, 8 }, null, null);
            var path = new Path();

            path.AddRoundRect(new RectF(0, 0, Width, Height), box.CornerRadius, box.CornerRadius, Path.Direction.Ccw);
            double width  = 0;
            double height = 0;

            if (box.Orientation == GradientOrientation.Horizontal)
            {
                width = Width;
            }
            else
            {
                height = Height;
            }
            // var gradientDrawable =  new GradientDrawable(GradientDrawable.Orientation.BlTr, );

            //var gradient = new Android.Graphics.LinearGradient((float)box.StartPointX, (float)box.StartPointY, (float)box.EndPointX, (float)box.EndPointY,
            float StartPointX, StartPointY, EndPointX, EndPointY = 0;

            StartPointX = ((float)Width * (float)box.StartPointX);
            StartPointY = ((float)Height * (float)box.StartPointY);
            EndPointX   = ((float)Width * (float)box.EndPointX);
            EndPointY   = ((float)Height * (float)box.EndPointY);

            //var gradient = new Android.Graphics.LinearGradient((float)box.StartPointX, (float)box.StartPointY, (float)width, (float)height,
            var gradient = new Android.Graphics.LinearGradient(StartPointX, StartPointY, EndPointX, EndPointY,

                                                               box.StartColor.ToAndroid(),
                                                               box.EndColor.ToAndroid(),
                                                               Android.Graphics.Shader.TileMode.Clamp);

            var paint = new Android.Graphics.Paint()
            {
                Dither = true,
            };



            paint.SetShader(gradient);
            canvas.DrawPath(path, paint);

            // canvas.DrawPath();

            //GradientDrawable.Bounds = canvas.ClipBounds;
            //GradientDrawable.SetOrientation(GradientContentView.Orientation == GradientOrientation.Vertical
            //    ? GradientDrawable.Orientation.TopBottom
            //    : GradientDrawable.Orientation.LeftRight);
            //GradientDrawable.Draw(canvas);



            return(base.DrawChild(canvas, child, drawingTime));
        }
Esempio n. 45
0
        private void DrawRing(Canvas c)
        {
            var sc = c.Save();

            c.Rotate(-this.Degree, c.Width / 2, c.Height / 2);

            //���ĵ�
            var cx = c.Width / 2;
            var cy = c.Height / 2;

            //������Բ Path ����һ�� Բ����ʾ����, ���ڿ���Բ
            var pInner = new Path();
            pInner.AddCircle(cx, cy, this.BitmapRadius + SPACE / 2, Path.Direction.Cw);
            var pOut = new Path();
            pOut.AddCircle(cx, cy, this.Radius, Path.Direction.Cw);

            c.ClipPath(pOut);
            c.ClipPath(pInner, Region.Op.Difference);

            //var color = new Color((int)(DateTime.Now.Ticks % 0xFFFFFFFF));
            //c.DrawColor(color);

            //�ýǶȽ��������Բ�ķ�Χ
            var g = new SweepGradient(cx, cy, Color.Green, Color.Transparent);
            var paint = new Paint();
            paint.SetShader(g);
            c.DrawCircle(cx, cy, this.Radius, paint);

            c.RestoreToCount(sc);
        }
Esempio n. 46
0
        private void DrawCenter(Canvas c)
        {
            var x = c.Width / 2;
            var y = c.Height / 2;
            var paint = new Paint() {
                Color = Color.White,
                AntiAlias = true
            };

            //���Խ���
            //var g = new LinearGradient(x - 30, y - 30, x + 30, y + 30, Color.Red, Color.Blue, Shader.TileMode.Mirror);

            // �ǶȽ���
            // ��һ��,�ڶ���������ʾ����Բ��������
            //var g = new SweepGradient(x, y, Color.Red, Color.Blue);

            //�����
            //��һ��,�ڶ���������ʾ����Բ��������,������������ʾ�뾶
            var g = new RadialGradient(x, y, 60, Color.Red, Color.Purple, Shader.TileMode.Mirror);
            paint.SetShader(g);

            c.DrawCircle(x, y, 60, paint);
            paint.Color = Color.Green;
            c.DrawCircle(x, y, 50, paint);
        }
Esempio n. 47
0
 private void SetupPaint()
 {
     mPaint.SetStyle(Paint.Style.Fill);
     mPaint.SetShader(new LinearGradient(mBallSideOffsets, 0, Width - mBallSideOffsets, 0, mColors, mPositions, Shader.TileMode.Clamp));
 }
        public ColorPickerView(Context c, int color)
            : base(c)
        {
            colors = new[] {
                new Color(255, 0, 0, 255).ToArgb(), new Color(255, 0, 255, 255).ToArgb(), new Color(0, 0, 255, 255).ToArgb(),
                new Color(0, 255, 255, 255).ToArgb(), new Color(0, 255, 0, 255).ToArgb(), new Color(255, 255, 0, 255).ToArgb(),
                new Color(255, 0, 0, 255).ToArgb()
            };

            bwcolors = new [] {
                new Color(255, 255, 255, 255).ToArgb(),
                new Color(127, 127, 127, 255).ToArgb(),
                new Color(0, 0, 0, 255).ToArgb()
            };

            strokeWidth = 100;

            if (wowZapp.LaffOutOut.Singleton.resizeFonts)
            {
                strokeWidth = ImageHelper.convertDpToPixel((25 * (float)wowZapp.LaffOutOut.Singleton.ScreenXWidth) / 100, c);
                width = height = Convert.ToInt32(strokeWidth * 2) - 20;
            } else
            {
                width = 180;
                height = 190;
            }

            Shader s = new SweepGradient(0, 0, colors, null);
            myPaint = new Paint(PaintFlags.AntiAlias);
            myPaint.SetShader(s);
            myPaint.SetStyle(Paint.Style.Stroke);
            myPaint.StrokeWidth = strokeWidth;

            myCenterPaint = new Paint(PaintFlags.AntiAlias);
            myCenterPaint.Color = colorFromInt(color);
            myCenterPaint.StrokeWidth = 0;
        }
		public static Bitmap ToTransformedCorners(Bitmap source, double topLeftCornerSize, double topRightCornerSize, double bottomLeftCornerSize, double bottomRightCornerSize, 
			CornerTransformType cornersTransformType, double cropWidthRatio, double cropHeightRatio)
		{
			double sourceWidth = source.Width;
			double sourceHeight = source.Height;

			double desiredWidth = sourceWidth;
			double desiredHeight = sourceHeight;

			double desiredRatio = cropWidthRatio / cropHeightRatio;
			double currentRatio = sourceWidth / sourceHeight;

			if (currentRatio > desiredRatio)
			{
				desiredWidth = (cropWidthRatio * sourceHeight / cropHeightRatio);
			}
			else if (currentRatio < desiredRatio)
			{
				desiredHeight = (cropHeightRatio * sourceWidth / cropWidthRatio);
			}

			topLeftCornerSize = topLeftCornerSize * (desiredWidth + desiredHeight) / 2 / 100;
			topRightCornerSize = topRightCornerSize * (desiredWidth + desiredHeight) / 2 / 100;
			bottomLeftCornerSize = bottomLeftCornerSize * (desiredWidth + desiredHeight) / 2 / 100;
			bottomRightCornerSize = bottomRightCornerSize * (desiredWidth + desiredHeight) / 2 / 100;

			float cropX = (float)((sourceWidth - desiredWidth) / 2);
			float cropY = (float)((sourceHeight - desiredHeight) / 2);

			Bitmap bitmap = Bitmap.CreateBitmap((int)desiredWidth, (int)desiredHeight, Bitmap.Config.Argb8888);

			using (Canvas canvas = new Canvas(bitmap))
			using (Paint paint = new Paint())
			using (BitmapShader shader = new BitmapShader(source, Shader.TileMode.Clamp, Shader.TileMode.Clamp))
			using (Matrix matrix = new Matrix())
			using (var path = new Path())
			{
				if (cropX != 0 || cropY != 0)
				{
					matrix.SetTranslate(-cropX, -cropY);
					shader.SetLocalMatrix(matrix);
				}

				paint.SetShader(shader);
				paint.AntiAlias = true;

				// TopLeft
				if (cornersTransformType.HasFlag(CornerTransformType.TopLeftCut)) 
				{
					path.MoveTo(0, (float)topLeftCornerSize);
					path.LineTo((float)topLeftCornerSize, 0);
				}
				else if (cornersTransformType.HasFlag(CornerTransformType.TopLeftRounded)) 
				{
					path.MoveTo(0, (float)topLeftCornerSize);
					path.QuadTo(0, 0, (float)topLeftCornerSize, 0);
				}
				else
				{
					path.MoveTo(0, 0);
				}

				// TopRight
				if (cornersTransformType.HasFlag(CornerTransformType.TopRightCut)) 
				{
					path.LineTo((float)(desiredWidth - topRightCornerSize), 0);
					path.LineTo((float)desiredWidth, (float)topRightCornerSize);
				}
				else if (cornersTransformType.HasFlag(CornerTransformType.TopRightRounded))
				{
					path.LineTo((float)(desiredWidth - topRightCornerSize), 0);
					path.QuadTo((float)desiredWidth, 0, (float)desiredWidth, (float)topRightCornerSize);
				}
				else
				{
					path.LineTo((float)desiredWidth ,0);
				}

				// BottomRight
				if (cornersTransformType.HasFlag(CornerTransformType.BottomRightCut)) 
				{
					path.LineTo((float)desiredWidth, (float)(desiredHeight - bottomRightCornerSize));
					path.LineTo((float)(desiredWidth - bottomRightCornerSize), (float)desiredHeight);
				}
				else if (cornersTransformType.HasFlag(CornerTransformType.BottomRightRounded))
				{
					path.LineTo((float)desiredWidth, (float)(desiredHeight - bottomRightCornerSize));
					path.QuadTo((float)desiredWidth, (float)desiredHeight, (float)(desiredWidth - bottomRightCornerSize), (float)desiredHeight);
				}
				else
				{
					path.LineTo((float)desiredWidth, (float)desiredHeight);
				}

				// BottomLeft
				if (cornersTransformType.HasFlag(CornerTransformType.BottomLeftCut)) 
				{
					path.LineTo((float)bottomLeftCornerSize, (float)desiredHeight);
					path.LineTo(0, (float)(desiredHeight - bottomLeftCornerSize));
				}
				else if (cornersTransformType.HasFlag(CornerTransformType.BottomLeftRounded)) 
				{
					path.LineTo((float)bottomLeftCornerSize, (float)desiredHeight);
					path.QuadTo(0, (float)desiredHeight, 0, (float)(desiredHeight - bottomLeftCornerSize));
				}
				else
				{
					path.LineTo(0, (float)desiredHeight);
				}

				path.Close();
				canvas.DrawPath(path, paint);

				return bitmap;				
			}
		}