コード例 #1
0
ファイル: SVGRectParser.cs プロジェクト: jdluzen/xamsvg
		public static void parse(SVGProperties pSVGProperties, Canvas pCanvas, SVGPaint pSVGPaint, RectF pRect) {
			float x = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_X, 0f);
			float y = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_Y, 0f);
			float width = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_WIDTH, 0f);
			float height = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_HEIGHT, 0f);

			pRect.Set(x, y, x + width, y + height);

			float? rX = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_RADIUS_X);
			float? rY = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_RADIUS_Y);

			bool rXSpecified = rX != null && rX >= 0;
			bool rYSpecified = rY != null && rY >= 0;

			bool rounded = rXSpecified || rYSpecified;
			float rx;
			float ry;
			if(rXSpecified && rYSpecified) {
				rx = Math.Min(rX.Value, width * 0.5f);
				ry = Math.Min(rY.Value, height * 0.5f);
			} else if(rXSpecified) {
				ry = rx = Math.Min(rX.Value, width * 0.5f);
			} else if(rYSpecified) {
				rx = ry = Math.Min(rY.Value, height * 0.5f);
			} else {
				rx = 0;
				ry = 0;
			}

			bool fill = pSVGPaint.setFill(pSVGProperties);
			if (fill) {
				if(rounded) {
					pCanvas.DrawRoundRect(pRect, rx, ry, pSVGPaint.getPaint());
				} else {
					pCanvas.DrawRect(pRect, pSVGPaint.getPaint());
				}
			}

			bool stroke = pSVGPaint.setStroke(pSVGProperties);
			if (stroke) {
				if(rounded) {
					pCanvas.DrawRoundRect(pRect, rx, ry, pSVGPaint.getPaint());
				} else {
					pCanvas.DrawRect(pRect, pSVGPaint.getPaint());
				}
			}

			if(fill || stroke) {
				pSVGPaint.ensureComputedBoundsInclude(x, y, width, height);
			}
		}
コード例 #2
0
		/// <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)
			{				
			}				
		}
コード例 #3
0
ファイル: BorderEffect.cs プロジェクト: antixaker/ProgressBar
        void OnElementSizeChanged(object sender, EventArgs e)
        {
            var elem = sender as View;
            if (elem == null)
                return;

            var density = Resources.System.DisplayMetrics.Density;

            using (var imageBitmap = Bitmap.CreateBitmap((int)((elem.Width + 2) * density), (int)((elem.Height + 1) * density), Bitmap.Config.Argb8888))
            using (var canvas = new Canvas(imageBitmap))
            using (var paint = new Paint() { Dither = false, Color = Xamarin.Forms.Color.White.ToAndroid(), AntiAlias = true })
            {
                paint.Hinting = PaintHinting.On;
                paint.Flags = PaintFlags.AntiAlias;
                paint.SetStyle(Paint.Style.Stroke);
                paint.StrokeWidth = 2 * density;

                var height = (float)elem.Height;

                canvas.DrawRoundRect(new RectF(density, density, (float)(elem.Width) * density, (float)(height) * density), height * density / 2, height * density / 2, paint);
                canvas.Density = (int)density;

                Container.Background = new BitmapDrawable(imageBitmap);
            }
        }
コード例 #4
0
		// If you would like to create a circle of the image set pixels to half the width of the image.
		internal static   Bitmap GetRoundedCornerBitmap(Bitmap bitmap, int pixels)
		{
			Bitmap output = null;

			try
			{
				output = Bitmap.CreateBitmap(bitmap.Width, bitmap.Height, Bitmap.Config.Argb8888);
				Canvas canvas = new Canvas(output);

				Color color = new Color(66, 66, 66);
				Paint paint = new Paint();
				Rect rect = new Rect(0, 0, bitmap.Width, bitmap.Height);
				RectF rectF = new RectF(rect);
				float roundPx = pixels;

				paint.AntiAlias = true;
				canvas.DrawARGB(0, 0, 0, 0);
				paint.Color = color;
				canvas.DrawRoundRect(rectF, roundPx, roundPx, paint);

				paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcIn));
				canvas.DrawBitmap(bitmap, rect, rect, paint);
			}
			catch (System.Exception err)
			{
				System.Console.WriteLine ("GetRoundedCornerBitmap Error - " + err.Message);
			}

			return output;
		}
コード例 #5
0
 protected override void OnDraw(Canvas canvas)
 {
     Android.Graphics.Drawable.Drawable drawable = GetDrawable();
     if (drawable is BitmapDrawable)
     {
         RectF rectF = new RectF(drawable.GetBounds());
         int restoreCount = canvas.SaveLayer(rectF, null, Canvas.AllSaveFlag);
         GetImageMatrix().MapRect(rectF);
         Paint paint = ((BitmapDrawable)drawable).GetPaint();
         paint.SetAntiAlias(true);
         paint.SetColor(unchecked((int)(0xff000000)));
         canvas.DrawARGB(0, 0, 0, 0);
         canvas.DrawRoundRect(rectF, Radius, Radius, paint);
         Xfermode restoreMode = paint.GetXfermode();
         paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcIn));
         base.OnDraw(canvas);
         // Restore paint and canvas
         paint.SetXfermode(restoreMode);
         canvas.RestoreToCount(restoreCount);
     }
     else
     {
         base.OnDraw(canvas);
     }
 }
コード例 #6
0
        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;
            }
        }
コード例 #7
0
ファイル: Shape.cs プロジェクト: asj-it/Xamarin-Forms-Shape
		protected virtual void HandleShapeDraw (Canvas canvas)
		{
			// We need to account for offsetting the coordinates based on the padding
			var x = GetX () + Resize (this.ShapeView.Padding.Left);
			var y = GetY () + Resize (this.ShapeView.Padding.Top);

			switch (ShapeView.ShapeType) {
			case ShapeType.Box:
				HandleStandardDraw (canvas, p => {
					var rect = new RectF (x, y, x + this.Width, y + this.Height);
					if (ShapeView.CornerRadius > 0) {
						var cr = Resize (ShapeView.CornerRadius);
						canvas.DrawRoundRect (rect, cr, cr, p);
					} else {
						canvas.DrawRect (rect, p);
					}
				});
				break;
			case ShapeType.Circle:
				HandleStandardDraw (canvas, p => canvas.DrawCircle (x + this.Width / 2, y + this.Height / 2, (this.Width - 10) / 2, p));
				break;
			case ShapeType.CircleIndicator:
				HandleStandardDraw (canvas, p => canvas.DrawCircle (x + this.Width / 2, y + this.Height / 2, (this.Width - 10) / 2, p), drawFill: false);
				HandleStandardDraw (canvas, p => canvas.DrawArc (new RectF (x, y, x + this.Width, y + this.Height), QuarterTurnCounterClockwise, 360 * (ShapeView.IndicatorPercentage / 100), false, p), ShapeView.StrokeWidth + 3, false);
				break;
			}
		}
コード例 #8
0
		public override void Draw(Canvas canvas)
		{
			RoundedBoxView rbv = (RoundedBoxView)this.Element;

			Rect rc = new Rect();
			GetDrawingRect(rc);

			Rect interior = rc;
			interior.Inset((int)rbv.StrokeThickness, (int)rbv.StrokeThickness);

			// The shadow is fairly pointless on Android as the bounds are clipped. You can add support
			// if you need to, but it is best to not do something like that on the Native interface

			#region Drawing the Shadow

//			if (rbv.HasShadow) {
//				Paint shadowPaint = new Paint () {
//					Color = Xamarin.Forms.Color.FromRgba(0.0, 0.0, 0.0, 0.5).ToAndroid (),
//					AntiAlias = true
//				};
//
//				var shadowOffset = 5.0;
//
//				var shadowRect = new Rect (rc);
//				shadowRect.Offset ((int)shadowOffset, (int)shadowOffset);
//
//				canvas.DrawRoundRect(
//					new RectF(shadowRect), (float)rbv.CornerRadius, (float)rbv.CornerRadius, shadowPaint);
//			}

			#endregion

			Paint p = new Paint() {
				Color = rbv.Color.ToAndroid(),
				AntiAlias = true,
			};

			canvas.DrawRoundRect(new RectF(interior), (float)rbv.CornerRadius, (float)rbv.CornerRadius, p);

			p.Color = rbv.Stroke.ToAndroid();
			p.StrokeWidth = (float)rbv.StrokeThickness;
			p.SetStyle(Paint.Style.Stroke);

			canvas.DrawRoundRect(new RectF(rc), (float)rbv.CornerRadius, (float)rbv.CornerRadius, p);
		}
コード例 #9
0
            void DrawOutline(ACanvas canvas, int width, int height, float cornerRadius, float outlineWidth)
            {
                using (var paint = new Paint {
                    AntiAlias = true
                })
                    using (var rect = new RectF(0, 0, width, height))
                    {
                        paint.StrokeWidth = outlineWidth;
                        paint.SetStyle(Paint.Style.Fill);
                        paint.Color = _frame.OutlineColor.ToAndroid();
                        canvas.DrawRoundRect(rect, cornerRadius, cornerRadius, paint);

                        // This will "carve out" the center where our background layer will go. Therefore we maintain the proper background color/transparency.
                        using (var clearXfer = new PorterDuffXfermode(PorterDuff.Mode.Clear))
                        {
                            paint.SetXfermode(clearXfer);
                            rect.Left = outlineWidth; rect.Top = outlineWidth; rect.Right = width - outlineWidth; rect.Bottom = height - outlineWidth;
                            canvas.DrawRoundRect(rect, cornerRadius, cornerRadius, paint);
                        }
                    }
            }
コード例 #10
0
 void DrawBackground(ACanvas canvas, int width, int height, float cornerRadius, float outlineWidth, bool pressed)
 {
     using (var paint = new Paint {
         AntiAlias = true
     })
         using (var rect = new RectF(outlineWidth, outlineWidth, width - outlineWidth, height - outlineWidth))
         {
             paint.SetStyle(Paint.Style.Fill);
             paint.Color = _frame.BackgroundColor.ToAndroid();
             canvas.DrawRoundRect(rect, cornerRadius, cornerRadius, paint);
         }
 }
コード例 #11
0
        public override void Draw(Canvas canvas)
        {
            RoundedGrid rg = (RoundedGrid)this.Element;

            Rect rc = new Rect ();
            GetDrawingRect (rc);

            Rect interior = rc;
            interior.Inset((int)rg.StrokeThickness, (int)rg.StrokeThickness);

            Paint p = new Paint () {
                Color = rg.BackgroundColor.ToAndroid(),
                AntiAlias = true
            };

            canvas.DrawRoundRect (new RectF (interior), (float)rg.CornerRadius, (float)rg.CornerRadius, p);

            p.Color = rg.Stroke.ToAndroid ();
            p.StrokeWidth = (float)rg.StrokeThickness;
            p.SetStyle(Paint.Style.Stroke);

            canvas.DrawRoundRect(new RectF(rc), (float)rg.CornerRadius, (float)rg.CornerRadius, p);
        }
コード例 #12
0
        public override void Draw(Android.Graphics.Canvas canvas)
        {
            var box   = Element as RoundedBoxView;
            var rect  = new Rect();
            var paint = new Paint()
            {
                Color     = box.BorderColor.ToAndroid(),
                AntiAlias = true,
            };

            paint.SetStyle(Paint.Style.Fill);
            GetDrawingRect(rect);
            var radius = (float)(rect.Width() / box.Width * box.CornerRadius);

            canvas.DrawRoundRect(new RectF(rect), radius, radius, paint);

            rect.Top    = rect.Top + Convert.ToInt32(box.BorderSize);
            rect.Bottom = rect.Bottom - Convert.ToInt32(box.BorderSize);
            rect.Left   = rect.Left + Convert.ToInt32(box.BorderSize);
            rect.Right  = rect.Right - Convert.ToInt32(box.BorderSize);
            paint.Color = box.BackgroundColor.ToAndroid();
            canvas.DrawRoundRect(new RectF(rect), radius, radius, paint);
        }
コード例 #13
0
ファイル: BitmapExtensions.cs プロジェクト: okrotowa/Yorsh
 public static Bitmap GetRoundedCornerBitmap(this Bitmap bitmap, int roundPixelSize)
 {
     Bitmap output = Bitmap.CreateBitmap(bitmap.Width, bitmap.Height, Bitmap.Config.Argb8888);
     var canvas = new Canvas(output);
     var paint = new Paint();
     var rect = new Rect(0, 0, bitmap.Width, bitmap.Height);
     var rectF = new RectF(rect);
     var roundPx = roundPixelSize;
     paint.AntiAlias = true;
     canvas.DrawRoundRect(rectF,roundPx,roundPx, paint);
     paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcIn));
     canvas.DrawBitmap(bitmap, rect, rect, paint);
     return output;
 }
コード例 #14
0
		public override void Draw(Canvas canvas)
		{
			var box = Element as RoundedBox;
			var rect = new Rect();
			var paint = new Paint() {
				Color = box.BackgroundColor.ToAndroid(),
				AntiAlias = true,
			};

			GetDrawingRect(rect);

			var radius = (float)(rect.Width() / box.Width * box.CornerRadius);

			canvas.DrawRoundRect(new RectF(rect), radius, radius, paint);
		}
コード例 #15
0
 public static Bitmap GetRoundedCornerBitmap(this Bitmap bitmap, int? roundPixelSize = null)
 {
     var chooseSize = bitmap.Width > bitmap.Height ? bitmap.Height : bitmap.Width;
     roundPixelSize = roundPixelSize ?? (int)Application.Context.Resources.GetDimension(Resource.Dimension.RoundedCorners);
     var output = Bitmap.CreateBitmap(chooseSize, chooseSize, Bitmap.Config.Argb8888);
     var canvas = new Canvas(output);
     var paint = new Paint();
     var rect = new Rect(0, 0, chooseSize, chooseSize);
     var rectF = new RectF(rect);
     var roundPx = roundPixelSize.Value;
     paint.AntiAlias = true;
     canvas.DrawRoundRect(rectF, roundPx, roundPx, paint);
     paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcIn));
     canvas.DrawBitmap(bitmap, rect, rect, paint);
     return output;
 }
コード例 #16
0
        public override void Draw(Canvas canvas)
        {
            var box = Element as CustomRoundedBox;
            var rect = new Rect();
            var paint = new Paint
            {
                AntiAlias = true,
            };
            paint.SetARGB((int)box.BackgroundColor.A, (int)box.BackgroundColor.R, (int)box.BackgroundColor.G, (int)box.BackgroundColor.B);

            GetDrawingRect(rect);

            var radius = (float)(rect.Width() / box.Width * box.CornerRadius);

            canvas.DrawRoundRect(new RectF(rect), radius, radius, paint);
        }
コード例 #17
0
        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;
        }
コード例 #18
0
        public override void Draw(Canvas canvas)
        {
            var box = Element as RoundedBox;
            var rect = new Rect();
            var androidColor = box.BackgroundColor.ToAndroid();
            var paint = new Paint()
                {
                    AntiAlias = true,
                };

            paint.SetARGB(Convert.ToInt32(box.Opacity * 255), (int)androidColor.R, (int)androidColor.G, (int)androidColor.B);

            GetDrawingRect(rect);

            var radius = (float)(rect.Width() / box.Width * box.CornerRadius);

            canvas.DrawRoundRect(new RectF(rect), radius, radius, paint);
        }
コード例 #19
0
		public override void Draw (Canvas canvas)
		{
			child.Draw (canvas);
			if (count <= 0)
				return;
			badgePaint.Alpha = textPaint.Alpha = alpha;
			badgeBounds.Set (0, 0, Bounds.Width () / 2, Bounds.Height () / 2);
			canvas.DrawRoundRect (badgeBounds, 8, 8, badgePaint);
			textPaint.TextSize = (8 * badgeBounds.Height ()) / 10;
			var text = count.ToString ();
			textPaint.GetTextBounds (text, 0, text.Length, txtBounds);
			canvas.DrawText (
				text,
				badgeBounds.CenterX (),
				badgeBounds.Bottom - (badgeBounds.Height () - txtBounds.Height ()) / 2 - 1,
				textPaint
			);
		}
コード例 #20
0
 protected override void DrawRightThumb(Android.Graphics.Canvas p0, float x1, float y1, float x2, float y2)
 {
     float density = Context.Resources.DisplayMetrics.Density;
     Paint paint = new Paint();
     paint.AntiAlias = true;
     RectF rounderRectF = new RectF(x2 - (1.66f * density), y2 - (3.33f * density), x2 + (16.66f * density), y2 + (16.66f * density));
     paint.Color = (Color.ParseColor("#5f6872"));
     p0.DrawRoundRect(rounderRectF, 7, 7, paint);
     Path path = new Path();
     path.MoveTo(x2, y2 - (16.66f * density));
     path.LineTo(x2, y2);
     path.LineTo(x2 + (16.66f * density), y2 - (2 * density));
     path.Close();
     p0.DrawPath(path, paint);
     paint.StrokeWidth = (3.33f * density);
     p0.DrawLine(x1, y1, x2, y2, paint);
     SetRightThumbBounds(new RectF(x2 - 25, y1 - 25, x2 + 25, y2 + 25));
 }
コード例 #21
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;
            }
        }
コード例 #22
0
ファイル: CornerRadius.cs プロジェクト: antixaker/ProgressBar
        void RedRaw(View view)
        {
            var density = Resources.System.DisplayMetrics.Density;

            using (var imageBitmap = Bitmap.CreateBitmap((int)(view.Width * density), (int)(view.Height * density), Bitmap.Config.Argb8888))
            using (var canvas = new Canvas(imageBitmap))
            using (var paint = new Paint() { Dither = false, Color = view.BackgroundColor.ToAndroid(), AntiAlias = true })
            {
                paint.Hinting = PaintHinting.On;
                paint.Flags = PaintFlags.AntiAlias;

                var height = (float)view.Height;

                canvas.DrawRoundRect(new RectF(0, 0, (float)view.Width * density, height * density), height * density / 2, height * density / 2, paint);
                canvas.Density = (int)density;

                Container.Background = new BitmapDrawable(imageBitmap);
            }
        }
コード例 #23
0
        protected override void Draw(Canvas canvas, Rect bounds)
        {
            int saveCount = canvas.Save();

            RectF arcBounds = mCurrentBounds;

            arcBounds.Set(bounds);

            //draw draw gas tube
            mPaint.Color = new Color(mGasTubeColor);
            mPaint.SetStyle(Paint.Style.Stroke);
            mPaint.StrokeWidth = mStrokeWidth;
            canvas.DrawPath(CreateGasTubePath(mGasTubeBounds), mPaint);

            //draw balloon
            mPaint.Color = new Color(mBalloonColor);
            mPaint.SetStyle(Paint.Style.FillAndStroke);
            canvas.DrawPath(CreateBalloonPath(mBalloonBounds, mProgress), mPaint);

            //draw progress
            mPaint.Color       = new Color(mGasTubeColor);
            mPaint.TextSize    = mTextSize;
            mPaint.StrokeWidth = mStrokeWidth / 5.0f;
            canvas.DrawText(mProgressText, arcBounds.CenterX() - mProgressBounds.Width() / 2.0f, mGasTubeBounds.CenterY() + mProgressBounds.Height() / 2.0f, mPaint);

            //draw cannula
            mPaint.Color = new Color(mCannulaColor);
            mPaint.SetStyle(Paint.Style.Stroke);
            mPaint.StrokeWidth = mStrokeWidth;
            canvas.DrawPath(CreateCannulaHeadPath(mCannulaBounds), mPaint);
            mPaint.SetStyle(Paint.Style.Fill);
            canvas.DrawPath(CreateCannulaBottomPath(mCannulaBounds), mPaint);

            //draw pipe body
            mPaint.Color = new Color(mPipeBodyColor);
            mPaint.SetStyle(Paint.Style.Fill);
            canvas.DrawRoundRect(mPipeBodyBounds, mRectCornerRadius, mRectCornerRadius, mPaint);

            canvas.RestoreToCount(saveCount);
        }
コード例 #24
0
        private void drawHuePanel(Canvas canvas)
        {
            /*
             * Drawn with hw acceleration, very fast.
             */

            //long start = SystemClock.elapsedRealtime();

            RectF rect = mHueRect;

            if (BORDER_WIDTH_PX > 0)
            {
                mBorderPaint.Color = new Color((int)mBorderColor);
                canvas.DrawRect(rect.Left - BORDER_WIDTH_PX,
                        rect.Top - BORDER_WIDTH_PX,
                        rect.Right + BORDER_WIDTH_PX,
                        rect.Bottom + BORDER_WIDTH_PX,
                        mBorderPaint);
            }

            if (mHueShader == null)
            {
                //The hue shader has either not yet been created or the view has been resized.
                mHueShader = new LinearGradient(0, 0, 0, rect.Height(), buildHueColorArray(), null, Shader.TileMode.Clamp);
                mHuePaint.SetShader(mHueShader);
            }

            canvas.DrawRect(rect, mHuePaint);

            float rectHeight = 4 * mDensity / 2;

            Point p = hueToPoint(mHue);

            RectF r = new RectF
            {
                Left = rect.Left - RECTANGLE_TRACKER_OFFSET,
                Right = rect.Right + RECTANGLE_TRACKER_OFFSET,
                Top = p.Y - rectHeight,
                Bottom = p.Y + rectHeight
            };

            canvas.DrawRoundRect(r, 2, 2, mHueAlphaTrackerPaint);

            //Log.d("mColorPicker", "Draw Time Hue: " + (SystemClock.elapsedRealtime() - start) + "ms");
        }
コード例 #25
0
 public override void Draw(Canvas canvas)
 {
     if (_mOval)
     {
         if (_mBorderWidth > 0)
         {
             canvas.DrawOval(_mDrawableRect, _mBitmapPaint);
             canvas.DrawOval(_mBorderRect, _mBorderPaint);
         }
         else
         {
             canvas.DrawOval(_mDrawableRect, _mBitmapPaint);
         }
     }
     else
     {
         if (_mBorderWidth > 0)
         {
             canvas.DrawRoundRect(_mDrawableRect, Math.Max(_mCornerRadius, 0),
                 Math.Max(_mCornerRadius, 0), _mBitmapPaint);
             canvas.DrawRoundRect(_mBorderRect, _mCornerRadius, _mCornerRadius, _mBorderPaint);
         }
         else
         {
             canvas.DrawRoundRect(_mDrawableRect, _mCornerRadius, _mCornerRadius, _mBitmapPaint);
         }
     }
 }
コード例 #26
0
		private void drawHuePanel(Canvas canvas){
			/*
		 * Drawn with hw acceleration, very fast.
		 */

			//long start = SystemClock.elapsedRealtime();

			RectF rect = mHueRect;

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

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

			if (mHueShader == null) {
				//The hue shader has either not yet been created or the view has been resized.
				mHueShader = new LinearGradient(0, 0, 0, rect.Height(), buildHueColorArray(), null, Android.Graphics.Shader.TileMode.Clamp);
				mHuePaint.SetShader(mHueShader);			
			}

			canvas.DrawRect(rect, mHuePaint);

			float rectHeight = 4 * mDensity / 2;

			Point p = hueToPoint(mHue);

			RectF r = new RectF();
			r.Left = rect.Left - RECTANGLE_TRACKER_OFFSET;
			r.Right = rect.Right + RECTANGLE_TRACKER_OFFSET;
			r.Top = p.Y - rectHeight;
			r.Bottom = p.Y + rectHeight;


			canvas.DrawRoundRect(r, 2, 2, mHueAlphaTrackerPaint);

			//Log.d("mColorPicker", "Draw Time Hue: " + (SystemClock.elapsedRealtime() - start) + "ms");

		}
コード例 #27
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;
        }
コード例 #28
0
		/// <Docs>The Canvas to which the View is rendered.</Docs>
		/// <summary>
		/// Draw the specified canvas.
		/// </summary>
		/// <param name="canvas">Canvas to draw onto.</param>
		public override void Draw(Canvas canvas)
		{
			BadgeImage image = (BadgeImage)Element;

			// Set color of icon
			if (Control.Drawable != null)
			{
				if (image.Selected)
				{
					Control.Drawable.SetColorFilter(filterColor);
				}
				else
				{
					Control.Drawable.SetColorFilter(filterGray);
				}
			}

			base.Draw(canvas);

			if (image.Number > 0)
			{
				using (Paint paint = new Paint())
				{
					paint.Color = image.Selected ? Xamarin.Forms.Color.Red.ToAndroid() : Xamarin.Forms.Color.Gray.ToAndroid();
					paint.StrokeWidth = 0f;
					paint.SetStyle(Paint.Style.FillAndStroke);

					// Calc text size
					paint.TextSize = (int)this.DipToPixel(16);
					paint.FakeBoldText = true;

					string text = image.Number.ToString();
					Rect textBounds = new Rect(0, 0, 0, 0);

					paint.GetTextBounds(text, 0, text.Length, textBounds);

					float textWidth = paint.MeasureText(text);
					float textHeight = textBounds.Height();

					float badgeWidth = textWidth + this.DipToPixel(9);
					float badgeHeight = textHeight + this.DipToPixel(9);

					if (badgeWidth < badgeHeight)
					{
						badgeWidth = badgeHeight;
					}

					double offsetX = (image.Bounds.Width - image.Bounds.Width) / 2;
					double offsetY = (image.Bounds.Height - image.Bounds.Height) / 2;

					float left = this.DipToPixel(image.Bounds.Width) - badgeWidth;
					float top = 1;
					float right = left + badgeWidth;
					float bottom = top + badgeHeight;
					float radius = (badgeHeight / 2f) - 1f;

					using (Path path = new Path())
					{
						canvas.DrawRoundRect(new RectF(left, top, left + badgeWidth, top + badgeHeight), radius, radius, paint);

						paint.Color = Xamarin.Forms.Color.White.ToAndroid();

						canvas.DrawText(image.Number.ToString(), left + ((badgeWidth - textWidth) / 2) - 1, bottom - ((badgeHeight - textHeight) / 2), paint);
					}
				}
			}
		}
コード例 #29
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();
        }
コード例 #30
0
		public override void Draw (Canvas canvas)
		{
			canvas.DrawRoundRect (bounds, radius, radius, paint);
		}
コード例 #31
0
		public override void Draw (Canvas canvas)
		{
			canvas.DrawRoundRect (mRect, mCornerRadius, mCornerRadius, strokePaint);
			canvas.DrawRoundRect (mRect, mCornerRadius, mCornerRadius, paint);
		}
コード例 #32
0
        /// <summary>
        /// Reshapes the image.
        /// </summary>
        /// <param name="sourceBitmap">The source bitmap.</param>
        private void ReshapeImage(Bitmap sourceBitmap)
        {
            if (sourceBitmap == null) return;

            using (var sourceRect = GetScaledRect(sourceBitmap.Height, sourceBitmap.Width))
            using (var rect = this.GetTargetRect(sourceBitmap.Height, sourceBitmap.Width))
            using (var output = Bitmap.CreateBitmap(rect.Width(), rect.Height(), Bitmap.Config.Argb8888))
            using (var canvas = new Canvas(output))
            using (var paint = new Paint())
            using (var rectF = new RectF(rect))
            {
                var roundRx = rect.Width() / 2;
                var roundRy = rect.Height() / 2;

                paint.AntiAlias = true;
                canvas.DrawARGB(0, 0, 0, 0);
                paint.Color = Android.Graphics.Color.ParseColor("#ff424242");
                canvas.DrawRoundRect(rectF, roundRx, roundRy, paint);

                paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcIn));
                canvas.DrawBitmap(sourceBitmap, sourceRect, rect, paint);

                //this.DrawBorder(canvas, rect.Width(), rect.Height());

                this.Control.SetImageBitmap(output);
                // Forces the internal method of InvalidateMeasure to be called.
                this.Element.WidthRequest = this.Element.WidthRequest;
            }
        }
コード例 #33
0
		private void drawAlphaPanel(Canvas canvas) {
			/*
		 * Will be drawn with hw acceleration, very fast.
		 */

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

			RectF rect = mAlphaRect;

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

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


			mAlphaPattern.Draw(canvas);

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

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


			mAlphaPaint.SetShader(mAlphaShader);

			canvas.DrawRect(rect, mAlphaPaint);

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

			float rectWidth = 4 * mDensity / 2;

			Point p = alphaToPoint(mAlpha);

			RectF r = new RectF();
			r.Left = p.X - rectWidth;
			r.Right = p.X + rectWidth;
			r.Top = rect.Top - RECTANGLE_TRACKER_OFFSET;
			r.Bottom = rect.Bottom + RECTANGLE_TRACKER_OFFSET;

			canvas.DrawRoundRect(r, 2, 2, mHueAlphaTrackerPaint);
		}
コード例 #34
0
		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;				
			}
		}
        private static Bitmap GetRoundedCornerBitmap(Bitmap bitmap, int roundPixels, Rect srcRect, Rect destRect, int width,
			    int height)
        {
            Bitmap output = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888);
            Canvas canvas = new Canvas(output);

            Paint paint = new Paint();
            RectF destRectF = new RectF(destRect);

            paint.AntiAlias = true;
            canvas.DrawARGB(0, 0, 0, 0);
            paint.Color = Color.Argb(0xFF, 0x00, 0x00, 0x00);
            canvas.DrawRoundRect(destRectF, roundPixels, roundPixels, paint);

            paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcIn));
            canvas.DrawBitmap(bitmap, srcRect, destRectF, paint);

            return output;
        }