private void drawResultPoints(Bitmap barcode, ZXing.Result rawResult) { var points = rawResult.ResultPoints; if (points != null && points.Length > 0) { var canvas = new Canvas(barcode); Paint paint = new Paint(); paint.Color = Android.Graphics.Color.White; paint.StrokeWidth = 3.0f; paint.SetStyle(Paint.Style.Stroke); var border = new RectF(2, 2, barcode.Width - 2, barcode.Height - 2); canvas.DrawRect(border, paint); paint.Color = Android.Graphics.Color.Purple; if (points.Length == 2) { paint.StrokeWidth = 4.0f; drawLine(canvas, paint, points[0], points[1]); } else if (points.Length == 4 && (rawResult.BarcodeFormat == BarcodeFormat.UPC_A || rawResult.BarcodeFormat == BarcodeFormat.EAN_13)) { // Hacky special case -- draw two lines, for the barcode and metadata drawLine(canvas, paint, points[0], points[1]); drawLine(canvas, paint, points[2], points[3]); } else { paint.StrokeWidth = 10.0f; foreach (ResultPoint point in points) canvas.DrawPoint(point.X, point.Y, paint); } } }
private void DrawPoint(Canvas canvas) { var metrics = Resources.DisplayMetrics; var widthInPixels = metrics.WidthPixels; var heightInPixels = metrics.HeightPixels; var x = canvas.Width; var y = canvas.Height; _StartPt.X = (_StartPt.X*x)/widthInPixels ; _StartPt.Y = (_StartPt.Y*y)/heightInPixels ; canvas.DrawPoint(_StartPt.X,_StartPt.Y, _Paint); }