I'm wondering if there was a way to display an annotation accurately (i.e. highlight or other) over a 1D barcode that's been detected on the page.
I've seen your demo on how to draw a rectangle on an image (from https://www.gdpicture.com/guides/gdpicture/web ... deX1.html) but I don't want to use this method as I have to reload the image every time I want to clear the rectangle so instead I thought I'd use an annotation but I can't get this to work, well not accurately anyway.
When calling 'Barcode1DReaderDoScan', I use the same method as per example from the above url i.e.
Code: Select all
oGdPictureImaging.Barcode1DReaderGetBarcodeX1(i) + LeftArea
I assume these values are returned in Pixels rather than Inches so before creating the annotation I call the following code:
Code: Select all
int dpi = 96;
float topLeftX = ((barcode.TopLeftPoints.X / dpi) + (float)this.LeftArea / dpi);
float topLeftY = (barcode.TopLeftPoints.Y / dpi) + (float)this.TopArea / dpi;
float topRightX = (barcode.TopRightPoints.X / dpi) + (float)this.LeftArea / dpi;
float topRightY = (barcode.TopRightPoints.Y / dpi) + (float)this.TopArea / dpi;
float bottomRightX = (barcode.BottomRightPoints.X / dpi) + (float)this.LeftArea / dpi;
float bottomRightY = (barcode.BottomRightPoints.Y / dpi) + (float)this.TopArea / dpi;
float bottomLeftX = (barcode.BottomLeftPoints.X / dpi) + (float)this.LeftArea / dpi;
float bottomLeftY = (barcode.BottomLeftPoints.Y / dpi) + (float)this.TopArea / dpi;
To add the annotation, I simply call the following:
AnnotationManager annotationManager = GdViewer1.GetAnnotationManager();
RectangleF rect = new RectangleF(topLeftX, topLeftY, bottomLeftX - topLeftX, bottomRightY - topLeftY);
var annotation = manager.AddRectangleHighlighterAnnot(Color.Yellow, rect.Left, rect.Top, rect.Width, rect.Height);
The problem I'm having with the above is that the highlighting annotation position is inconsistent. On some barcodes it's nearly perfectly over the barcode, and on some others it's completely off or too short and this seems to vary depending on the image resolution/image type? I'm trying it out on different images (.tiff/.jpg) I got from the web.
Is there a way to accurately cover a barcode with an annotation based on the barcode coordinates?
Thanks.
Thierry