Read & Recognize Barcode From Local Images In .NET Applications


SUBMITTED BY: Guest

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

FORMAT: C#

SIZE: 1.9 kB

HITS: 1116

  1. //build URI to upload file
  2. string fileUploadUri = "http://api.saaspose.com/v1.0/storage/file/test.jpg";
  3. string UploadUrl = Sign(fileUploadUri);
  4. // Send request to upload file
  5. UploadFileBinary("c:\\temp\\test.jpg", UploadUrl, "PUT");
  6. //build URI to read barcode
  7. string strURI = "http://api.saaspose.com/v1.0/barcode/test.jpg/recognize?type=AllSupportedTypes";
  8. // Send the request to Saaspose server
  9. Stream responseStream = ProcessCommand(Sign(strURI), "GET");
  10. StreamReader reader = new StreamReader(responseStream);
  11. // Read the response
  12. string strJSON = reader.ReadToEnd();
  13. //Parse the json string to JObject
  14. JObject parsedJSON = JObject.Parse(strJSON);
  15. //Deserializes the JSON to a object.
  16. RecognitionResponse barcodeRecognitionResponse = JsonConvert.DeserializeObject<RecognitionResponse>(parsedJSON.ToString());
  17. // Display the value and type of all the recognized barcodes
  18. foreach (RecognizedBarCode barcode in barcodeRecognitionResponse.Barcodes)
  19. {
  20. Console.WriteLine("Codetext: " + barcode.BarCodeValue + "\nType: " + barcode.BarCodeType);
  21. }
  22. \\Here is the RecognitionResponse class
  23. public class RecognitionResponse : BaseResponse
  24. {
  25. public List<RecognizedBarCode> Barcodes { get; set; }
  26. }
  27. \\Here is the RecognizedBarCode class
  28. public class RecognizedBarCode
  29. {
  30. public string BarCodeType { get; set; }
  31. public string BarCodeValue { get; set; }
  32. }
  33. \\Here is the BaseResponse class
  34. public class BaseResponse
  35. {
  36. public BaseResponse() { }
  37. public string Code { get; set; }
  38. public string Status { get; set; }
  39. }

comments powered by Disqus