Read BarCodes In The Image & Get BarCode Region Information From Image


SUBMITTED BY: Guest

DATE: June 12, 2013, 1:17 a.m.

FORMAT: C#

SIZE: 2.1 kB

HITS: 876

  1. [C#]
  2. // read code39 barcode from image
  3. string image = "code39Extended.jpg";
  4. BarCodeReader reader = new BarCodeReader(image, BarCodeReadType.Code39Standard);
  5. // try to recognize all possible barcodes in the image
  6. while (reader.Read()) {
  7. // get the region information
  8. BarCodeRegion region = reader.GetRegion();
  9. if (region != null)
  10. {
  11. // display x and y coordinates of barcode detected
  12. System.Drawing.Point[] point = region.Points;
  13. Console.WriteLine("Top left coordinates: X = " + point[0].X + ", Y = " + point[0].Y);
  14. Console.WriteLine("Bottom left coordinates: X = " + point[1].X + ", Y = " + point[1].Y);
  15. Console.WriteLine("Bottom right coordinates: X = " + point[2].X + ", Y = " + point[2].Y);
  16. Console.WriteLine("Top right coordinates: X = " + point[3].X + ", Y = " + point[3].Y);
  17. }
  18. Console.WriteLine("Codetext: " + reader.GetCodeText());
  19. }
  20. // close reader
  21. reader.Close();
  22. [VB.NET]
  23. ' read code39 barcode from image
  24. Dim image As String = "code39Extended.jpg"
  25. Dim reader As New BarCodeReader(image, BarCodeReadType.Code39Standard)
  26. ' try to recognize all possible barcodes in the image
  27. While reader.Read()
  28. ' get the region information
  29. Dim region As BarCodeRegion = reader.GetRegion()
  30. If region IsNot Nothing Then
  31. ' display x and y coordinates of barcode detected
  32. Dim point As System.Drawing.Point() = region.Points
  33. Console.WriteLine("Top left coordinates: X = " & point(0).X & ", Y = " & point(0).Y)
  34. Console.WriteLine("Bottom left coordinates: X = " & point(1).X & ", Y = " & point(1).Y)
  35. Console.WriteLine("Bottom right coordinates: X = " & point(2).X & ", Y = " & point(2).Y)
  36. Console.WriteLine("Top right coordinates: X = " & point(3).X & ", Y = " & point(3).Y)
  37. End If
  38. Console.WriteLine("Codetext: " & reader.GetCodeText())
  39. End While
  40. ' close reader
  41. reader.Close()

comments powered by Disqus