/// <summary> /// Draws barcode referenced points. /// </summary> /// <param name="canvas">The canvas.</param> /// <param name="barcodeInfo">The barcode.</param> /// <param name="paint">The paint information.</param> private void DrawBarcodeReferencePoints(Canvas canvas, IBarcodeInfo barcodeInfo, Paint paint) { BarcodeInfo2D barcodeInfo2D = barcodeInfo as BarcodeInfo2D; // if barcode is 2D barcode if (barcodeInfo2D != null) { float cellSize = (float)(barcodeInfo2D.CellWidth + barcodeInfo2D.CellHeight) / 2; if (cellSize > 15) { cellSize = 15; } foreach (System.Drawing.PointF point in barcodeInfo2D.GetReferencePoints()) { canvas.DrawCircle(point.X, point.Y, cellSize / 2, paint); } } }
/// <summary> /// Draws the barcode information. /// </summary> /// <param name="canvas">A canvas.</param> /// <param name="paint">A paint information.</param> /// <param name="barcodeInfo">A barcode.</param> /// <param name="scale">A scale value.</param> private void DrawBarcodeInfo(Canvas canvas, Paint paint, IBarcodeInfo barcodeInfo, float scale) { int alpha; // get barcode region Region barcodeRegion = barcodeInfo.Region; if (barcodeRegion == null) { return; } // determines whether barcode region should be filled bool fill; // if confidence of barcode recognition is "-1" if (barcodeInfo.Confidence == -1) { alpha = 48; paint.Color = Color.LimeGreen; fill = true; } // if confidence of barcode recognition is no less than "95" else if (barcodeInfo.Confidence >= 95) { alpha = 64; paint.Color = Color.LimeGreen; fill = true; } // if confidence of barcode recognition between 0 and 95 else { paint.Color = Color.Red; BarcodeInfo2D barcodeInfo2D = barcodeInfo as BarcodeInfo2D; if (barcodeInfo2D != null && barcodeInfo2D.GetReferencePoints().Length > 0) { alpha = 64; fill = false; } else { alpha = 32; fill = true; } } // if barcode region should be filled if (fill) { paint.Alpha = alpha; // fill barcode region FillRegion(canvas, barcodeInfo.Region, paint); } paint.Alpha = alpha * 3; // if confidence of barcode recognition is no less than "95" if (barcodeInfo.Confidence >= 95) { paint.Color = Color.Orange; } // draw barcode reference points DrawBarcodeReferencePoints(canvas, barcodeInfo, paint); // if need draw barcode type if (barcodeInfo.BarcodeInfoClass == BarcodeInfoClass.Barcode2D || barcodeInfo.Confidence == -1 || barcodeInfo.Confidence >= 95) { // get barcode type name string text = Utils.GetBarcodeTypeString(barcodeInfo); // draw barcode type name DrawText(canvas, barcodeInfo.Region.Rectangle, text, _textSizeInPixels / scale, paint.Color, 255, true); } }