void Initialize () { mPaint = new Paint (); mPaint.Color = Color.Black; mPaint.AntiAlias = true; mPaint.SetStyle (Paint.Style.Fill); }
protected override void Draw(Canvas canvas, Rect bounds) { int saveCount = canvas.Save(); for (int i = 0; i < mBallCount; i++) { if (i == mSwapIndex) { mPaint.SetStyle(Paint.Style.Fill); canvas.DrawCircle(mBallSideOffsets + mBallRadius * (i * 2 + 1) + i * mBallInterval + mSwapBallOffsetX, mBallCenterY - mSwapBallOffsetY, mBallRadius, mPaint); } else if (i == (mSwapIndex + 1) % mBallCount) { mPaint.SetStyle(Paint.Style.Stroke); canvas.DrawCircle(mBallSideOffsets + mBallRadius * (i * 2 + 1) + i * mBallInterval - mSwapBallOffsetX, mBallCenterY + mSwapBallOffsetY, mBallRadius - mStrokeWidth / 2, mPaint); } else { mPaint.SetStyle(Paint.Style.Stroke); canvas.DrawCircle(mBallSideOffsets + mBallRadius * (i * 2 + 1) + i * mBallInterval, mBallCenterY, mBallRadius - mStrokeWidth / 2, mPaint); } } canvas.RestoreToCount(saveCount); }
/// <summary> /// Draw the annotations on the Bitmap /// </summary> /// <param name="bmp">The image where annotations will be drawn to</param> /// <param name="annotations">The annotations to be drawn</param> public static void DrawAnnotations(Android.Graphics.Bitmap bmp, Annotation[] annotations = null) { if (annotations != null) { using (Android.Graphics.Paint p = new Android.Graphics.Paint()) using (Canvas c = new Canvas(bmp)) { p.AntiAlias = true; p.Color = Android.Graphics.Color.Red; p.TextSize = 20; for (int i = 0; i < annotations.Length; i++) { p.SetStyle(Paint.Style.Stroke); float[] rects = ScaleLocation(annotations[i].Rectangle, bmp.Width, bmp.Height); Android.Graphics.Rect r = new Rect((int)rects[0], (int)rects[1], (int)rects[2], (int)rects[3]); c.DrawRect(r, p); p.SetStyle(Paint.Style.Fill); c.DrawText(annotations[i].Label, (int)rects[0], (int)rects[1], p); } } } }
private void SetupPaint() { mPaint.AntiAlias = true; mPaint.StrokeWidth = mStrokeWidth; mPaint.SetStyle(Paint.Style.Stroke); mPaint.StrokeCap = Paint.Cap.Round; SetInsets((int)Width, (int)Height); }
protected override void OnDraw(Android.Graphics.Canvas canvas) { Paint paint = new Paint () { Color = Color.ForestGreen, StrokeWidth = 5 }; for (int i = 0; i < maxLevel; i++) { if (i < Level) paint.SetStyle (Paint.Style.Fill); else paint.SetStyle (Paint.Style.Stroke); canvas.DrawCircle (canvas.Height / 2 + canvas.Height*i , canvas.Height / 2, canvas.Height / 2 - 5, paint); } }
/// <Docs>The Canvas to which the View is rendered.</Docs> /// <summary> /// Draw the specified canvas. /// </summary> /// <param name="canvas">Canvas.</param> public override void Draw (Canvas canvas) { try { var element = Element as RoundCornerView; var cornerRadius = (float)element.CornerRadius*Resources.DisplayMetrics.Density; // Paint rounded rect itself canvas.Save(); var paint = new Paint(); paint.AntiAlias = true; var strokeWidth = (((float)element.BorderWidth)*Resources.DisplayMetrics.Density); paint.StrokeWidth = strokeWidth; if(element.BackgroundColor != Xamarin.Forms.Color.Transparent) { paint.SetStyle(Paint.Style.Fill); paint.Color = element.BackgroundColor.ToAndroid(); canvas.DrawRoundRect(new RectF(0, 0, Width, Height), cornerRadius, cornerRadius, paint); } if(element.BorderColor != Xamarin.Forms.Color.Transparent) { paint.SetStyle(Paint.Style.Stroke); paint.Color = element.BorderColor.ToAndroid(); canvas.DrawRoundRect(new RectF(0, 0, Width, Height), cornerRadius, cornerRadius, paint); } //Properly dispose paint.Dispose(); canvas.Restore(); // Create clip path var path = new Path(); path.AddRoundRect(new RectF(0.0f + (strokeWidth/2), 0.0f + (strokeWidth/2), Width - (strokeWidth/2), Height - (strokeWidth/2)), cornerRadius, cornerRadius, Path.Direction.Cw); canvas.Save(); canvas.ClipPath(path); // Do base drawing for(var i=0; i<ChildCount; i++) GetChildAt(i).Draw(canvas); canvas.Restore(); path.Dispose(); } catch (Exception) { } }
public CirclePageIndicator(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle) { //Load defaults from resources var res = Resources; int defaultPageColor = res.GetColor(Resource.Color.default_circle_indicator_page_color); int defaultFillColor = res.GetColor(Resource.Color.default_circle_indicator_fill_color); int defaultOrientation = res.GetInteger(Resource.Integer.default_circle_indicator_orientation); int defaultStrokeColor = res.GetColor(Resource.Color.default_circle_indicator_stroke_color); float defaultStrokeWidth = res.GetDimension(Resource.Dimension.default_circle_indicator_stroke_width); float defaultRadius = res.GetDimension(Resource.Dimension.default_circle_indicator_radius); bool defaultCentered = res.GetBoolean(Resource.Boolean.default_circle_indicator_centered); bool defaultSnap = res.GetBoolean(Resource.Boolean.default_circle_indicator_snap); //Retrieve styles attributes var a = context.ObtainStyledAttributes(attrs, Resource.Styleable.CirclePageIndicator, defStyle, Resource.Style.Widget_CirclePageIndicator); mCentered = a.GetBoolean(Resource.Styleable.CirclePageIndicator_vpiCentered, defaultCentered); mOrientation = a.GetInt(Resource.Styleable.CirclePageIndicator_vpiOrientation, defaultOrientation); mPaintPageFill = new Paint(PaintFlags.AntiAlias); mPaintPageFill.SetStyle(Paint.Style.Fill); mPaintPageFill.Color = a.GetColor(Resource.Styleable.CirclePageIndicator_vpiPageColor, defaultPageColor); mPaintStroke = new Paint(PaintFlags.AntiAlias); mPaintStroke.SetStyle(Paint.Style.Stroke); mPaintFill = new Paint(PaintFlags.AntiAlias); mPaintFill.SetStyle(Paint.Style.Fill); mSnap = a.GetBoolean(Resource.Styleable.CirclePageIndicator_vpiSnap, defaultSnap); mRadius = a.GetDimension(Resource.Styleable.CirclePageIndicator_vpiRadius, defaultRadius); mPaintFill.Color = a.GetColor(Resource.Styleable.CirclePageIndicator_vpiFillColor, defaultFillColor); mPaintStroke.Color = a.GetColor(Resource.Styleable.CirclePageIndicator_vpiStrokeColor, defaultStrokeColor); mPaintStroke.StrokeWidth = a.GetDimension(Resource.Styleable.CirclePageIndicator_vpiStrokeWidth, defaultStrokeWidth); a.Recycle(); }
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); } }
public DrawingImageView(Context context, Fragment fragment): base(context) { mPaint = new Paint(); mPaint.AntiAlias = true; mPaint.Dither = true; mPaint.Color = Color.Yellow; mPaint.SetStyle (Paint.Style.Stroke); mPaint.StrokeJoin = Paint.Join.Round; mPaint.StrokeCap = Paint.Cap.Round; mPaint.StrokeWidth = 10; cPaint = new Paint (); cPaint.Color = Color.Yellow; cPaint.StrokeJoin = Paint.Join.Round; cPaint.StrokeCap = Paint.Cap.Round; cPaint.SetTypeface(Typeface.Default); cPaint.TextSize = 40; mPath = new Android.Graphics.Path(); mBitmapPaint = new Paint(); mBitmapPaint.Color = Color.Yellow; DrawingStatus = DrawingType.None; _fragment = fragment; }
protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime) { try { var radius = Math.Min(Width, Height) / 2; var strokeWidth = 10; radius -= strokeWidth / 2; //Create path to clip var path = new Path(); path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw); canvas.Save(); canvas.ClipPath(path); var result = base.DrawChild(canvas, child, drawingTime); canvas.Restore(); // Create path for circle border path = new Path(); path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw); var paint = new Paint(); paint.AntiAlias = true; paint.StrokeWidth = 5; paint.SetStyle(Paint.Style.Stroke); paint.Color = global::Android.Graphics.Color.White; canvas.DrawPath(path, paint); //Properly dispose paint.Dispose(); path.Dispose(); return result; } catch (Exception ex) { Console.WriteLine("Unable to create circle image: " + ex); } return base.DrawChild(canvas, child, drawingTime); }
public override void Draw(Canvas canvas) { paint = new Android.Graphics.Paint(); paint.SetStyle(Android.Graphics.Paint.Style.Stroke); paint.StrokeCap = Android.Graphics.Paint.Cap.Round; paint.StrokeJoin = Android.Graphics.Paint.Join.Round; if (_paths == null) { return; } foreach (var pathFromModel in _paths) { if (pathFromModel?.Points == null || pathFromModel.Points.Count < 2) { continue; } paint.SetARGB(255, pathFromModel.Color.Red, pathFromModel.Color.Green, pathFromModel.Color.Blue); paint.StrokeWidth = pathFromModel.LineWidth; var path = new Android.Graphics.Path(); path.MoveTo(pathFromModel.Points[0].X, pathFromModel.Points[0].Y); for (int i = 1; i < pathFromModel.Points.Count; i++) { path.LineTo(pathFromModel.Points[i].X, pathFromModel.Points[i].Y); } canvas.DrawPath(path, paint); } }
protected override void OnDraw(Android.Graphics.Canvas canvas) { base.OnDraw(canvas); if (Borders != null) { Android.Graphics.Paint paint = new Android.Graphics.Paint(); paint.Color = Color.Black; paint.SetStyle(Android.Graphics.Paint.Style.Stroke); int Height = this.Height; int Width = this.Width; if (Borders.Top > 0) { paint.StrokeWidth = Borders.Top * 2; canvas.DrawLine(0, 0, Width, 0, paint); } if (Borders.Bottom > 0) { paint.StrokeWidth = Borders.Bottom * 2; canvas.DrawLine(0, Height, Width, Height, paint); } if (Borders.Left > 0) { paint.StrokeWidth = Borders.Left * 2; canvas.DrawLine(0, 0, 0, Height, paint); } if (Borders.Right > 0) { paint.StrokeWidth = Borders.Right * 2; canvas.DrawLine(Width, 0, Width, Height, paint); } paint.Dispose(); } }
public override void Draw(Canvas canvas) { LoadResources (); var blackPaint = new Paint () { Color = black.Value }; var whitePaint = new Paint () { Color = white.Value }; XamGame.RenderBoard ((RectangleF rect, Square.ColourNames color) => { var paint = color == Square.ColourNames.White ? whitePaint : blackPaint; canvas.DrawRect (rect.X, rect.Y, rect.Right, rect.Bottom, paint); }, (RectangleF rect, object image) => { if (image != null) canvas.DrawBitmap ((Bitmap) image, rect.Left, rect.Top, null); }); // New Game button whitePaint.Color = white.Value; whitePaint.SetStyle (Paint.Style.Fill); whitePaint.TextSize = 30; whitePaint.AntiAlias = true; Rect bounds = new Rect (); whitePaint.GetTextBounds ("New Game", 0, 8, bounds); canvas.DrawText ("New Game", (this.Width - bounds.Width ()) / 2, this.Bottom - (XamGame.BoardUpperLeftCorner.Y - bounds.Height ()) / 2, whitePaint); whitePaint.Dispose (); blackPaint.Dispose (); base.Draw (canvas); }
void Initialize () { _basePaint = new Paint (); _basePaint.Color = Color.Black; _basePaint.AntiAlias = true; _basePaint.SetStyle (Paint.Style.Fill); _gridPaint = new Paint (); _gridPaint.SetStyle (Paint.Style.Stroke); _gridPaint.Color = Color.ParseColor (RSColors.RS_LIGHT_GRAY); _circlesPaint = new Paint (); _circlesPaint.Color = Color.ParseColor (RSColors.PURPLE_4); _circlesPaint.SetStyle (Paint.Style.Fill); _circlesPaint.AntiAlias = true; _dataLabelPaint = new Paint (); _dataLabelPaint.Color = Color.ParseColor (RSColors.GREEN_4); _dataLabelPaint.TextSize = PixelUtil.GetPixelFromDP (dataLabelSize, _context.Resources); _dataLabelPaint.SetStyle (Paint.Style.Stroke); _dataLabelPaint.AntiAlias = true; _dataLabelPaint.SetTypeface (Typeface.DefaultBold); _dataLabelPaint.TextAlign = Paint.Align.Center; _dataLabelBgPaint = new Paint (); _dataLabelBgPaint.Color = Color.White; _dataLabelBgPaint.SetStyle (Paint.Style.Fill); _xLabelPaint = new Paint (); _xLabelPaint.Color = Color.Black; _xLabelPaint.SetStyle (Paint.Style.Stroke); _xLabelPaint.AntiAlias = true; _xLabelPaint.TextAlign = Paint.Align.Center; _xLabelPaint.TextSize = PixelUtil.GetPixelFromDP (xLabelSize, _context.Resources); }
protected override void OnDraw(Android.Graphics.Canvas canvas) { var rect = new RectF(0, 0, 300, 300); switch (Shape) { case Shape.Circle: canvas.DrawOval(rect, new Paint() { Color = Color.CornflowerBlue }); break; case Shape.Square: canvas.DrawRect(rect, new Paint() { Color = Color.Crimson }); break; case Shape.Triangle: var path = new Path(); path.MoveTo(rect.CenterX(), rect.Top); path.LineTo(rect.Left, rect.Bottom); path.LineTo(rect.Right, rect.Bottom); path.Close(); var paint = new Paint() {Color = Color.Crimson}; paint.Color = Color.Gold; paint.SetStyle(Paint.Style.Fill); canvas.DrawPath(path, paint); break; default: throw new ArgumentOutOfRangeException(); } }
private void SetupPaint() { mPaint.AntiAlias = true; mPaint.StrokeWidth = mStrokeWidth; mPaint.SetStyle(Paint.Style.Stroke); mPaint.StrokeCap = Paint.Cap.Round; }
private void Initialize() { var scaledDensity = Context.Resources.DisplayMetrics.ScaledDensity; SetLayerType(LayerType.Software, null); _paintBorder = new Paint(PaintFlags.AntiAlias) { Color = Color.DarkGray }; _paintGrid = new Paint(PaintFlags.AntiAlias) { Color = Color.LightGray }; _paintGrid.SetStyle(Paint.Style.Stroke); _paintGrid.SetPathEffect(new DashPathEffect(new float[] { 5, 5 }, 0)); _paintGrid.StrokeWidth = 5; _paintSubGrid = new Paint(PaintFlags.AntiAlias) { Color = Color.LightGray }; _paintSubGrid.SetStyle(Paint.Style.Stroke); _paintSubGrid.SetPathEffect(new DashPathEffect(new float[] { 5, 5 }, 0)); _paintSubGrid.StrokeWidth = 2; _paintPos = new Paint(PaintFlags.AntiAlias) { Color = Color.CornflowerBlue }; _paintGridText = new Paint(PaintFlags.AntiAlias) { Color = Color.LightGray, TextSize = 20*scaledDensity }; }
public override void Draw(Android.Graphics.Canvas canvas) { base.Draw (canvas); Paint mBgPaints = new Paint (); mBgPaints.AntiAlias = true; mBgPaints.SetStyle (Paint.Style.Fill); mBgPaints.Color = Color.Blue; mBgPaints.StrokeWidth = 0.5f; Paint tPaint = new Paint (); tPaint.Alpha = 0; canvas.DrawColor (tPaint.Color); RectF mOvals = new RectF (40, 40, layout.MeasuredWidth - 40, layout.MeasuredHeight - 40); decimal total = 0; foreach (SecuritiesViewModel.PieChartValue value in securitiesViewModel.DataForPieChart ()) { total += value.amount; } if (total == 0) { return; } decimal degressPerAmount = 360 / total; decimal currentAngle = 0; foreach (SecuritiesViewModel.PieChartValue value in securitiesViewModel.DataForPieChart ()) { canvas.DrawArc (mOvals, (float)currentAngle, (float)(degressPerAmount * value.amount), true, mBgPaints); currentAngle += (degressPerAmount * value.amount); mBgPaints.SetARGB (255, new Random ().Next (256), new Random ().Next (256), new Random ().Next (256)); } }
public override void Draw(Android.Graphics.Canvas canvas) { base.Draw(canvas); var rect = new RectF(0,0,300,300); switch (TheShape) { case Shape.Circle: canvas.DrawOval(rect, new Paint() { Color = Color.Aqua }); break; case Shape.Square: canvas.DrawRect(rect, new Paint() { Color = Color.Red }); break; case Shape.Triangle: var path = new Path(); path.MoveTo(rect.CenterX(), 0); path.LineTo(0, rect.Height()); path.LineTo(rect.Width(), rect.Height()); path.Close(); var paint = new Paint() {Color = Color.Magenta}; paint.SetStyle(Paint.Style.Fill); canvas.DrawPath(path, paint); break; default: throw new ArgumentOutOfRangeException(); } }
protected override void OnDraw(Canvas canvas) { base.OnDraw (canvas); var r = new Rect (); this.GetLocalVisibleRect (r); var half = r.Width() / 2; var height = r.Height(); var percentage = (this.Limit - Math.Abs(this.CurrentValue)) / this.Limit; var paint = new Paint() { Color = this.CurrentValue < 0 ? this.negativeColor : this.positiveColor, StrokeWidth = 5 }; paint.SetStyle(Paint.Style.Fill); if (this.CurrentValue < 0) { var start = (float)percentage * half; var size = half - start; canvas.DrawRect (new Rect ((int)start, 0, (int)(start + size), height), paint); } else { canvas.DrawRect (new Rect((int)half, 0, (int)(half + percentage * half), height), paint); } }
private static void DrawRectangle(Canvas canvas, RectF destination, Styles.Color outlineColor) { var paint = new Paint(); paint.SetStyle(Paint.Style.Stroke); paint.Color = new AndroidColor(outlineColor.R, outlineColor.G, outlineColor.B, outlineColor.A); paint.StrokeWidth = 4; canvas.DrawRect(destination, paint); }
private void Init() { mPaint = new Paint(); mPaint.Color = Resources.GetColor(Resource.Color.triangle); mPaint.AntiAlias = true; mPaint.SetStyle(Paint.Style.FillAndStroke); SetBackgroundColor(Resources.GetColor(Resource.Color.view_bg)); }
// we need this constructor for LayoutInflater public LinedEditText (Context context, IAttributeSet attrs) : base (context, attrs) { rect = new Rect (); paint = new Paint (); paint.SetStyle (Android.Graphics.Paint.Style.Stroke); paint.Color = Color.LightGray; }
protected override bool DrawChild(Canvas canvas, View child, long drawingTime) { try { var radius = Math.Min(Width, Height) / 2; var borderThickness = (float)((CircleImage)Element).BorderThickness; int strokeWidth = 0; if (borderThickness > 0) { var logicalDensity = Xamarin.Forms.Forms.Context.Resources.DisplayMetrics.Density; strokeWidth = (int)Math.Ceiling(borderThickness * logicalDensity + .5f); } radius -= strokeWidth / 2; var path = new Path(); path.AddCircle(Width / 2.0f, Height / 2.0f, radius, Path.Direction.Ccw); canvas.Save(); canvas.ClipPath(path); var paint = new Paint(); paint.AntiAlias = true; paint.SetStyle(Paint.Style.Fill); paint.Color = ((CircleImage)Element).FillColor.ToAndroid(); canvas.DrawPath(path, paint); paint.Dispose(); var result = base.DrawChild(canvas, child, drawingTime); canvas.Restore(); path = new Path(); path.AddCircle((float) Width / 2, (float) Height / 2, radius, Path.Direction.Ccw); if (strokeWidth > 0.0f) { paint = new Paint {AntiAlias = true, StrokeWidth = strokeWidth}; paint.SetStyle(Paint.Style.Stroke); paint.Color = ((CircleImage)Element).BorderColor.ToAndroid(); canvas.DrawPath(path, paint); paint.Dispose(); } path.Dispose(); return result; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Unable to create circle image: " + ex); } return base.DrawChild(canvas, child, drawingTime); }
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); } }
public object Create(Color color) { var result = new ag.Paint { Color = color.ToAndroid(), }; result.SetStyle(ag.Paint.Style.Fill); return result; }
protected override void OnDraw(Canvas canvas) { var paint = new Paint(); paint.SetARGB(255, 200, 255, 0); paint.SetStyle(Paint.Style.Stroke); paint.StrokeWidth = 4; canvas.DrawCircle (200, 200, 180, paint); }
private void SetupPaint() { mPaint.AntiAlias = true; mPaint.StrokeWidth = mStrokeWidth; mPaint.SetStyle(Paint.Style.Stroke); mPaint.StrokeCap = Paint.Cap.Round; InitStrokeInset(Width, Height); }
protected override void OnDraw(Canvas canvas) { base.OnDraw(canvas); Paint paint = new Paint { Color = Android.Graphics.Color.Blue }; paint.SetStyle(Paint.Style.Fill); canvas.DrawArc (_rect, 0, 300, true, paint); }
private ShapeDrawable CreateRectangle(Color color) { ShapeDrawable rect = new ShapeDrawable(new RectShape()); var paint = new Paint(); paint.SetARGB(255,color.R,color.G,color.B); paint.SetStyle(Paint.Style.Fill); paint.StrokeWidth = 4; rect.Paint.Set(paint); return rect; }
public object Create(Color color) { var result = new ag.Paint { Color = color.ToAndroid(), }; result.SetStyle(ag.Paint.Style.Fill); return(result); }
public CirclePageIndicator (Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle) { //Load defaults from resources var res = Resources; int defaultPageColor = res.GetColor (Resource.Color.default_circle_indicator_page_color); int defaultFillColor = res.GetColor (Resource.Color.default_circle_indicator_fill_color); int defaultOrientation = res.GetInteger (Resource.Integer.default_circle_indicator_orientation); int defaultStrokeColor = res.GetColor (Resource.Color.default_circle_indicator_stroke_color); float defaultStrokeWidth = res.GetDimension (Resource.Dimension.default_circle_indicator_stroke_width); float defaultRadius = res.GetDimension (Resource.Dimension.default_circle_indicator_radius); bool defaultCentered = res.GetBoolean (Resource.Boolean.default_circle_indicator_centered); bool defaultSnap = res.GetBoolean (Resource.Boolean.default_circle_indicator_snap); //Retrieve styles attributes try { var a = context.ObtainStyledAttributes (attrs, Resource.Styleable.CirclePageIndicator, defStyle, Resource.Style.Widget_CirclePageIndicator); mCentered = a.GetBoolean (Resource.Styleable.CirclePageIndicator_centered, defaultCentered); mOrientation = a.GetInt (Resource.Styleable.CirclePageIndicator_orientation, defaultOrientation); mPaintPageFill = new Paint (PaintFlags.AntiAlias); mPaintPageFill.SetStyle (Paint.Style.Fill); mPaintPageFill.Color = a.GetColor (Resource.Styleable.CirclePageIndicator_pageColor, defaultPageColor); mPaintStroke = new Paint (PaintFlags.AntiAlias); mPaintStroke.SetStyle (Paint.Style.Stroke); mPaintStroke.Color = a.GetColor (Resource.Styleable.CirclePageIndicator_strokeColor, defaultStrokeColor); mPaintStroke.StrokeWidth = a.GetDimension (Resource.Styleable.CirclePageIndicator_strokeWidth, defaultStrokeWidth); mPaintFill = new Paint (PaintFlags.AntiAlias); mPaintFill.SetStyle (Paint.Style.Fill); mPaintFill.Color = a.GetColor (Resource.Styleable.CirclePageIndicator_fillColor, defaultFillColor); mRadius = a.GetDimension (Resource.Styleable.CirclePageIndicator_radius, defaultRadius); mSnap = a.GetBoolean (Resource.Styleable.CirclePageIndicator_snap, defaultSnap); a.Recycle (); } catch { mCentered = defaultCentered; mOrientation = defaultOrientation; mPaintPageFill = new Paint (PaintFlags.AntiAlias); mPaintPageFill.SetStyle (Paint.Style.Fill); mPaintPageFill.Color = new Color(0,0,0,0); mPaintStroke = new Paint (PaintFlags.AntiAlias); mPaintStroke.SetStyle (Paint.Style.Stroke); mPaintStroke.Color = new Color(127,127,127); mPaintStroke.StrokeWidth = defaultStrokeWidth; mPaintFill = new Paint (PaintFlags.AntiAlias); mPaintFill.SetStyle (Paint.Style.Fill); mPaintFill.Color = new Color(255,173,58); mRadius = defaultRadius; mSnap = defaultSnap; } var configuration = ViewConfiguration.Get (context); mTouchSlop = Android.Support.V4.View.ViewConfigurationCompat.GetScaledPagingTouchSlop (configuration); }
private void DrawFocusRect(ISurfaceHolder holder, float RectLeft, float RectTop, float RectRight, float RectBottom, Android.Graphics.Color color) { //lock var canvas = holder.LockCanvas(); //no pointer to canvas? if (canvas == null) { return; } Log.Error(TAG, "\t\t --Drawing in canvas--"); /* * Rectangle rect = new Rectangle((int)RectLeft, (int)RectTop, (int)RectRight, (int)RectBottom); * var xCenter = (rect.X + rect.Width) / 2; * var yCenter = (rect.Y + rect.Height) / 2; */ //clear out canvas.Scale(vWidth / mPreviewSize.Width, vHeight / mPreviewSize.Height); if (CLEAR_CANVAS) { canvas.DrawColor(Android.Graphics.Color.Transparent, Android.Graphics.PorterDuff.Mode.Clear); } //border's properties var paint = new Android.Graphics.Paint(); paint.SetStyle(Android.Graphics.Paint.Style.Stroke); var text = new Paint(); text.TextSize = 20; paint.TextSize = 30; //paint.SetTextSize(20); paint.Color = color; paint.StrokeWidth = 3; canvas.DrawRect(RectLeft, RectTop, RectRight, RectBottom, paint); //DEBUG //canvas.DrawText("RectLeft:" + RectLeft, 0, 30, paint); //canvas.DrawText("RectTop:" + RectTop, 0, 60, paint); //canvas.DrawText("RectRight:" + RectRight, 0, 90, paint); //canvas.DrawText("RectBottom:" + RectBottom, 0, 120, paint); canvas.DrawText("Canvas:" + canvas.Width + "," + canvas.Height, 0, 30, paint); canvas.DrawText("Mat :" + mPreviewSize.Width + "," + mPreviewSize.Height, 0, 60, paint); canvas.DrawText("View :" + vWidth + "," + vHeight, 0, 90, paint); CLEAR_CANVAS = false; //unlock holder.UnlockCanvasAndPost(canvas); }
/// <summary> /// Read the file and draw rectangles on it. /// </summary> /// <param name="fileName">The name of the file.</param> /// <param name="annotations">Annotations to be add to the image. Can consist of rectangles and labels</param> /// <returns>The image in Jpeg stream format</returns> public static Emgu.Models.JpegData ImageFileToJpeg(String fileName, Annotation[] annotations = null) { using (BitmapFactory.Options options = new BitmapFactory.Options()) { options.InMutable = true; using (Android.Graphics.Bitmap bmp = BitmapFactory.DecodeFile(fileName, options)) { if (annotations != null) { using (Android.Graphics.Paint p = new Android.Graphics.Paint()) using (Canvas c = new Canvas(bmp)) { p.AntiAlias = true; p.Color = Android.Graphics.Color.Red; p.TextSize = 20; for (int i = 0; i < annotations.Length; i++) { p.SetStyle(Paint.Style.Stroke); float[] rects = ScaleLocation(annotations[i].Rectangle, bmp.Width, bmp.Height); Android.Graphics.Rect r = new Rect((int)rects[0], (int)rects[1], (int)rects[2], (int)rects[3]); c.DrawRect(r, p); p.SetStyle(Paint.Style.Fill); c.DrawText(annotations[i].Label, (int)rects[0], (int)rects[1], p); } } } using (MemoryStream ms = new MemoryStream()) { bmp.Compress(Bitmap.CompressFormat.Jpeg, 90, ms); JpegData result = new JpegData(); result.Raw = ms.ToArray(); result.Width = bmp.Width; result.Height = bmp.Height; return(result); } } } }
private void Init(Context context, IAttributeSet attrs) { Android.Content.Res.TypedArray attributes = context.ObtainStyledAttributes(attrs, Resource.Styleable.BorderedImageView, 0, 0); var color = attributes.GetColor(Resource.Styleable.BorderedImageView_bordered_color, Color.White); mBorderPaint = new Paint(); mBorderPaint.AntiAlias = true; mBorderPaint.SetStyle(Paint.Style.Stroke); mBorderPaint.Color = color; mBorderPaint.StrokeWidth = ImageLoading.Sample.MainActivity.DimensionHelper.DpToPx(STROKE_WIDTH_DP); }
public void DrawEllipse(RectF rect, Color fill, Color stroke, double thickness = 1) { using (var paint = new Paint()) { paint.AntiAlias = true; paint.StrokeWidth = (float)thickness; if (fill != null) { paint.SetStyle(Paint.Style.Fill); paint.Color = stroke; canvas.DrawOval(rect, paint); } if (stroke != null) { paint.SetStyle(Paint.Style.Stroke); paint.Color = stroke; canvas.DrawOval(rect, paint); } } }
protected TextBasedFlyoutBase(int p0,Color defaultColor = default(Color)) : base(p0) { TextPaint = new TextPaint { TextSize = 26, TextAlign = Paint.Align.Center }; TextPaint.AntiAlias = true; TextPaint.ElegantTextHeight = true; TextPaint.SetStyle(Paint.Style.Fill); TextPaint.Color = defaultColor == default(Color) ? TextColorBase : defaultColor; }
private void Init() { IsRunning = false; OutlineAlpha = 1.0f; outlinePaint = new Paint(); outlinePaint.AntiAlias = true; outlinePaint.StrokeWidth = Utils.Dp2Px(2); outlinePaint.Color = Resources.GetColor(Resource.Color.holo_blue); outlinePaint.SetStyle(Paint.Style.Stroke); var padding = Utils.Dp2Px(10); SetPadding(padding, padding, padding, padding); }
private static Paint ToAndroid(this Pen pen) { var paint = new Paint { AntiAlias = true, Color = pen.Color.ToAndroid(), StrokeWidth = (float)pen.Width, StrokeJoin = Paint.Join.Round }; paint.SetStyle(Paint.Style.Stroke); return paint; }
public CircularProgressDrawable(Color color, float borderWidth) { _borderWidth = borderWidth; _paint = new Paint(); _paint.AntiAlias = true; _paint.SetStyle(Paint.Style.Stroke); _paint.StrokeWidth = borderWidth; _paint.Color = color; SetupAnimations(); }
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); }
// --------------------------------------------------------- #region Overrides protected override void OnElementChanged(ElementChangedEventArgs <Image> e) { base.OnElementChanged(e); if (e.NewElement != null) { _formsView = (ManneDoForms.Components.PaintView.MannePaintView)e.NewElement; _currentPaint = new Android.Graphics.Paint(); _currentPaint.Dither = true; _currentPaint.SetStyle(Android.Graphics.Paint.Style.Stroke); _currentPaint.StrokeJoin = Android.Graphics.Paint.Join.Round; _currentPaint.StrokeCap = Android.Graphics.Paint.Cap.Round; _deviceDensity = AndroidDevice.DisplayMetrics.Density > 1 ? AndroidDevice.DisplayMetrics.Density : 1; } }
public override void Draw(Canvas canvas) { base.Draw(canvas); var paint = new Android.Graphics.Paint() { Dither = true, StrokeWidth = 4, AntiAlias = true, Color = Android.Graphics.Color.Gray }; paint.SetShadowLayer(20f, 0f, 0f, Android.Graphics.Color.Black); paint.SetStyle(Paint.Style.Stroke); var rect = new Android.Graphics.RectF(0, 0, Width, Height); canvas.DrawRoundRect(rect, Control.Radius, Control.Radius, paint); }
protected override void OnDraw(Canvas canvas) { var frame = Element as CustomizedFrame; var my1stPaint = new Android.Graphics.Paint(); var my2ndPaint = new Android.Graphics.Paint(); var backgroundPaint = new Android.Graphics.Paint(); my1stPaint.AntiAlias = true; my1stPaint.SetStyle(Paint.Style.Stroke); my1stPaint.StrokeWidth = frame.BorderWidth + 2; my1stPaint.Color = frame.BorderColor.ToAndroid(); my2ndPaint.AntiAlias = true; my2ndPaint.SetStyle(Paint.Style.Stroke); my2ndPaint.StrokeWidth = frame.BorderWidth; my2ndPaint.Color = frame.BackgroundColor.ToAndroid(); backgroundPaint.SetStyle(Paint.Style.Stroke); backgroundPaint.StrokeWidth = 4; backgroundPaint.Color = frame.BackgroundColor.ToAndroid(); Android.Graphics.Rect oldBounds = new Android.Graphics.Rect(); canvas.GetClipBounds(oldBounds); RectF oldOutlineBounds = new RectF(); oldOutlineBounds.Set(oldBounds); RectF myOutlineBounds = new RectF(); myOutlineBounds.Set(oldBounds); myOutlineBounds.Top += (int)my2ndPaint.StrokeWidth + 3; myOutlineBounds.Bottom -= (int)my2ndPaint.StrokeWidth + 3; myOutlineBounds.Left += (int)my2ndPaint.StrokeWidth + 3; myOutlineBounds.Right -= (int)my2ndPaint.StrokeWidth + 3; canvas.DrawRoundRect(oldOutlineBounds, 10, 10, backgroundPaint); //to "hide" old outline canvas.DrawRoundRect(myOutlineBounds, frame.CornerRadius, frame.CornerRadius, my1stPaint); canvas.DrawRoundRect(myOutlineBounds, frame.CornerRadius, frame.CornerRadius, my2ndPaint); base.OnDraw(canvas); }
public static void DrawResults(Android.Graphics.Bitmap bmp, MultiboxGraph.Result result, float scoreThreshold) { Rectangle[] locations = ScaleLocation(result.DecodedLocations, bmp.Width, bmp.Height); Android.Graphics.Paint p = new Android.Graphics.Paint(); p.SetStyle(Paint.Style.Stroke); p.AntiAlias = true; p.Color = Android.Graphics.Color.Red; Canvas c = new Canvas(bmp); for (int i = 0; i < result.Scores.Length; i++) { if (result.Scores[i] > scoreThreshold) { Rectangle rect = locations[result.Indices[i]]; Android.Graphics.Rect r = new Rect(rect.Left, rect.Top, rect.Right, rect.Bottom); c.DrawRect(r, p); } } }
private void Start() { CurrentLineColor = Color.Black; PenWidth = 5.0f; DrawPath = new Android.Graphics.Path(); DrawPaint = new Android.Graphics.Paint { Color = CurrentLineColor, AntiAlias = true, StrokeWidth = PenWidth }; DrawPaint.SetStyle(Android.Graphics.Paint.Style.Stroke); DrawPaint.StrokeJoin = Android.Graphics.Paint.Join.Round; DrawPaint.StrokeCap = Android.Graphics.Paint.Cap.Round; CanvasPaint = new Android.Graphics.Paint { Dither = true }; }
private void DrawFocusRect(ISurfaceHolder holder, float RectLeft, float RectTop, float RectRight, float RectBottom, Android.Graphics.Color color) { //lock var canvas = holder.LockCanvas(); //no pointer to canvas? if (canvas == null) { return; } //detect face FaceEyes FE = Detect(); //clear out canvas.DrawColor(Android.Graphics.Color.Transparent, Android.Graphics.PorterDuff.Mode.Clear); //border's properties var paint = new Android.Graphics.Paint(); paint.SetStyle(Android.Graphics.Paint.Style.Stroke); paint.Color = color; paint.StrokeWidth = 3; Rectangle e0 = FE.Eyes[0]; Rectangle e1 = FE.Eyes[1]; Rectangle f0 = FE.Faces[0]; canvas.DrawRect(new Rect(e0.Left, e0.Top, e0.Right, e0.Bottom), paint); canvas.DrawRect(new Rect(e1.Left, e1.Top, e1.Right, e1.Bottom), paint); paint.Color = Android.Graphics.Color.White; canvas.DrawRect(new Rect(f0.Left, f0.Top, f0.Right, f0.Bottom), paint); //unlock holder.UnlockCanvasAndPost(canvas); }
protected override void OnDraw(Canvas canvas) { coreX = Width / 2; coreY = Height / 2; roundRadius = (int)(Width / 2 * radiusDistance); //计算中心圆圈半径 RectF rect = new RectF(0, 0, Width, Height); if (roundMenus != null && roundMenus.Count > 0) { float sweepAngle = 360 / roundMenus.Count; //每个弧形的角度 deviationDegree = sweepAngle / 2; //其实的偏移角度,如果4个扇形的时候是X形状,而非+,设为0试试就知道什么意思了 for (int i = 0; i < roundMenus.Count; i++) { RoundMenu roundMenu = roundMenus[i]; //填充 Paint paint = new Paint(); paint.AntiAlias = true; if (onClickState == i) { //选中 paint.Color = new Color(roundMenu.selectSolidColor); } else { //未选中 paint.Color = new Color(roundMenu.solidColor); } canvas.DrawArc(rect, deviationDegree + (i * sweepAngle), sweepAngle, true, paint); //画描边 paint = new Paint(); paint.AntiAlias = true; paint.StrokeWidth = roundMenu.strokeSize; paint.SetStyle(Paint.Style.Stroke); paint.Color = new Color(roundMenu.strokeColor); canvas.DrawArc(rect, deviationDegree + (i * sweepAngle), sweepAngle, roundMenu.useCenter, paint); //画图案 Matrix matrix = new Matrix(); matrix.PostTranslate((float)((coreX + Width / 2 * roundMenu.iconDistance) - (roundMenu.icon.Width / 2)), coreY - (roundMenu.icon.Height / 2)); matrix.PostRotate(((i + 1) * sweepAngle), coreX, coreY); canvas.DrawBitmap(roundMenu.icon, matrix, null); } } //画中心圆圈 if (isCoreMenu) { //填充 RectF rect1 = new RectF(coreX - roundRadius, coreY - roundRadius, coreX + roundRadius, coreY + roundRadius); Paint paint = new Paint(); paint.AntiAlias = true; paint.StrokeWidth = coreMenuStrokeSize; if (onClickState == -1) { paint.Color = new Color(coreMenuSelectColor); } else { paint.Color = new Color(coreMenuColor); } canvas.DrawArc(rect1, 0, 360, true, paint); //画描边 paint = new Paint(); paint.AntiAlias = true; paint.StrokeWidth = coreMenuStrokeSize; paint.SetStyle(Paint.Style.Stroke); paint.Color = new Color(coreMenuStrokeColor); canvas.DrawArc(rect1, 0, 360, true, paint); if (coreBitmap != null) { //画中心圆圈的"OK"图标 canvas.DrawBitmap(coreBitmap, coreX - coreBitmap.Width / 2, coreY - coreBitmap.Height / 2, null); //在 0,0坐标开始画入src } } }
/// <summary> /// Read the file and draw rectangles on it. /// </summary> /// <param name="fileName">The name of the file.</param> /// <param name="annotations">Annotations to be add to the image. Can consist of rectangles and lables</param> /// <returns>The image in Jpeg stream format</returns> public static byte[] ImageFileToJpeg(String fileName, Annotation[] annotations = null) { #if __ANDROID__ BitmapFactory.Options options = new BitmapFactory.Options(); options.InMutable = true; Android.Graphics.Bitmap bmp = BitmapFactory.DecodeFile(fileName, options); Android.Graphics.Paint p = new Android.Graphics.Paint(); p.SetStyle(Paint.Style.Stroke); p.AntiAlias = true; p.Color = Android.Graphics.Color.Red; Canvas c = new Canvas(bmp); for (int i = 0; i < annotations.Length; i++) { float[] rects = ScaleLocation(annotations[i].Rectangle, bmp.Width, bmp.Height); Android.Graphics.Rect r = new Rect((int)rects[0], (int)rects[1], (int)rects[2], (int)rects[3]); c.DrawRect(r, p); } using (MemoryStream ms = new MemoryStream()) { bmp.Compress(Bitmap.CompressFormat.Jpeg, 90, ms); return(ms.ToArray()); } #elif __MACOS__ NSImage img = NSImage.ImageNamed(fileName); DrawAnnotations(img, annotations); /* * img.LockFocus(); * * NSColor redColor = NSColor.Red; * redColor.Set(); * var context = NSGraphicsContext.CurrentContext; * var cgcontext = context.CGContext; * cgcontext.ScaleCTM(1, -1); * cgcontext.TranslateCTM(0, -img.Size.Height); * //context.IsFlipped = !context.IsFlipped; * for (int i = 0; i < annotations.Length; i++) * { * float[] rects = ScaleLocation(annotations[i].Rectangle, (int)img.Size.Width, (int) img.Size.Height); * CGRect cgRect = new CGRect( * rects[0], * rects[1], * rects[2] - rects[0], * rects[3] - rects[1]); * NSBezierPath.StrokeRect(cgRect); * } * img.UnlockFocus(); */ var imageData = img.AsTiff(); var imageRep = NSBitmapImageRep.ImageRepsWithData(imageData)[0] as NSBitmapImageRep; var jpegData = imageRep.RepresentationUsingTypeProperties(NSBitmapImageFileType.Jpeg, null); byte[] jpeg = new byte[jpegData.Length]; System.Runtime.InteropServices.Marshal.Copy(jpegData.Bytes, jpeg, 0, (int)jpegData.Length); return(jpeg); #elif __IOS__ UIImage uiimage = new UIImage(fileName); UIGraphics.BeginImageContextWithOptions(uiimage.Size, false, 0); var context = UIGraphics.GetCurrentContext(); uiimage.Draw(new CGPoint()); context.SetStrokeColor(UIColor.Red.CGColor); context.SetLineWidth(2); for (int i = 0; i < annotations.Length; i++) { float[] rects = ScaleLocation( annotations[i].Rectangle, (int)uiimage.Size.Width, (int)uiimage.Size.Height); CGRect cgRect = new CGRect( (nfloat)rects[0], (nfloat)rects[1], (nfloat)(rects[2] - rects[0]), (nfloat)(rects[3] - rects[1])); context.AddRect(cgRect); context.DrawPath(CGPathDrawingMode.Stroke); } UIImage imgWithRect = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); var jpegData = imgWithRect.AsJPEG(); byte[] jpeg = new byte[jpegData.Length]; System.Runtime.InteropServices.Marshal.Copy(jpegData.Bytes, jpeg, 0, (int)jpegData.Length); return(jpeg); #else if (Emgu.TF.Util.Platform.OperationSystem == OS.Windows) { Bitmap img = new Bitmap(fileName); if (annotations != null) { using (Graphics g = Graphics.FromImage(img)) { for (int i = 0; i < annotations.Length; i++) { if (annotations[i].Rectangle != null) { float[] rects = ScaleLocation(annotations[i].Rectangle, img.Width, img.Height); PointF origin = new PointF(rects[0], rects[1]); RectangleF rect = new RectangleF(rects[0], rects[1], rects[2] - rects[0], rects[3] - rects[1]); Pen redPen = new Pen(Color.Red, 3); g.DrawRectangle(redPen, Rectangle.Round(rect)); String label = annotations[i].Label; if (label != null) { g.DrawString(label, new Font(FontFamily.GenericSansSerif, 20f), Brushes.Red, origin); } } } g.Save(); } } using (MemoryStream ms = new MemoryStream()) { img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); return(ms.ToArray()); } } else { throw new Exception("DrawResultsToJpeg Not implemented for this platform"); } #endif }
private void SetupPaint() { mPaint.SetStyle(Paint.Style.Fill); mPaint.SetShader(new LinearGradient(mBallSideOffsets, 0, Width - mBallSideOffsets, 0, mColors, mPositions, Shader.TileMode.Clamp)); }
public void FillRectangle(Paint p, float x, float y, float width, float height) { p.SetStyle(Paint.Style.Fill); this.canvas.DrawRect(x, y, x + width, y + height, p); }
private void SetupPaint() { mPaint.AntiAlias = true; mPaint.SetStyle(Paint.Style.Fill); mPaint.StrokeWidth = 1.0f; }
/// <summary> /// Read the file and draw rectangles on it. /// </summary> /// <param name="fileName">The name of the file.</param> /// <param name="annotations">Annotations to be add to the image. Can consist of rectangles and lables</param> /// <returns>The image in Jpeg stream format</returns> public static JpegData ImageFileToJpeg(String fileName, Annotation[] annotations = null) { #if __ANDROID__ BitmapFactory.Options options = new BitmapFactory.Options(); options.InMutable = true; Android.Graphics.Bitmap bmp = BitmapFactory.DecodeFile(fileName, options); Android.Graphics.Paint p = new Android.Graphics.Paint(); p.SetStyle(Paint.Style.Stroke); p.AntiAlias = true; p.Color = Android.Graphics.Color.Red; Canvas c = new Canvas(bmp); for (int i = 0; i < annotations.Length; i++) { float[] rects = ScaleLocation(annotations[i].Rectangle, bmp.Width, bmp.Height); Android.Graphics.Rect r = new Rect((int)rects[0], (int)rects[1], (int)rects[2], (int)rects[3]); c.DrawRect(r, p); } using (MemoryStream ms = new MemoryStream()) { bmp.Compress(Bitmap.CompressFormat.Jpeg, 90, ms); JpegData result = new JpegData(); result.Raw = ms.ToArray(); result.Width = bmp.Width; result.Height = bmp.Height; return(result); } #elif __MACOS__ NSImage img = NSImage.ImageNamed(fileName); if (annotations != null && annotations.Length > 0) { DrawAnnotations(img, annotations); } var imageData = img.AsTiff(); var imageRep = NSBitmapImageRep.ImageRepsWithData(imageData)[0] as NSBitmapImageRep; var jpegData = imageRep.RepresentationUsingTypeProperties(NSBitmapImageFileType.Jpeg, null); byte[] jpeg = new byte[jpegData.Length]; System.Runtime.InteropServices.Marshal.Copy(jpegData.Bytes, jpeg, 0, (int)jpegData.Length); JpegData result = new JpegData(); result.Raw = jpeg; result.Width = (int)img.Size.Width; result.Height = (int)img.Size.Height; return(result); #elif __IOS__ UIImage uiimage = new UIImage(fileName); UIGraphics.BeginImageContextWithOptions(uiimage.Size, false, 0); var context = UIGraphics.GetCurrentContext(); uiimage.Draw(new CGPoint()); context.SetStrokeColor(UIColor.Red.CGColor); context.SetLineWidth(2); for (int i = 0; i < annotations.Length; i++) { float[] rects = ScaleLocation( annotations[i].Rectangle, (int)uiimage.Size.Width, (int)uiimage.Size.Height); CGRect cgRect = new CGRect( (nfloat)rects[0], (nfloat)rects[1], (nfloat)(rects[2] - rects[0]), (nfloat)(rects[3] - rects[1])); context.AddRect(cgRect); context.DrawPath(CGPathDrawingMode.Stroke); } context.ScaleCTM(1, -1); context.TranslateCTM(0, -uiimage.Size.Height); for (int i = 0; i < annotations.Length; i++) { float[] rects = ScaleLocation( annotations[i].Rectangle, (int)uiimage.Size.Width, (int)uiimage.Size.Height); context.SelectFont("Helvetica", 18, CGTextEncoding.MacRoman); context.SetFillColor((nfloat)1.0, (nfloat)0.0, (nfloat)0.0, (nfloat)1.0); context.SetTextDrawingMode(CGTextDrawingMode.Fill); context.ShowTextAtPoint(rects[0], uiimage.Size.Height - rects[1], annotations[i].Label); } UIImage imgWithRect = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); var jpegData = imgWithRect.AsJPEG(); byte[] jpeg = new byte[jpegData.Length]; System.Runtime.InteropServices.Marshal.Copy(jpegData.Bytes, jpeg, 0, (int)jpegData.Length); JpegData result = new JpegData(); result.Raw = jpeg; result.Width = (int)uiimage.Size.Width; result.Height = (int)uiimage.Size.Height; return(result); #else Bitmap img = new Bitmap(fileName); if (annotations != null) { using (Graphics g = Graphics.FromImage(img)) { for (int i = 0; i < annotations.Length; i++) { if (annotations[i].Rectangle != null) { float[] rects = ScaleLocation(annotations[i].Rectangle, img.Width, img.Height); PointF origin = new PointF(rects[0], rects[1]); RectangleF rect = new RectangleF(origin, new SizeF(rects[2] - rects[0], rects[3] - rects[1])); Pen redPen = new Pen(Color.Red, 3); g.DrawRectangle(redPen, Rectangle.Round(rect)); String label = annotations[i].Label; if (label != null) { g.DrawString(label, new Font(FontFamily.GenericSansSerif, 20f), Brushes.Red, origin); } } } g.Save(); } } using (MemoryStream ms = new MemoryStream()) { img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); JpegData result = new JpegData(); result.Raw = ms.ToArray(); result.Width = img.Size.Width; result.Height = img.Size.Height; return(result); } #endif }