DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

David has posted 34 posts at DZone. View Full User Profile

Read & Recognize Barcode from Local Images in .NET Applications

03.13.2013
| 4308 views |
  • submit to reddit
//build URI to upload file
            string fileUploadUri = "http://api.saaspose.com/v1.0/storage/file/test.jpg";
            string UploadUrl = Sign(fileUploadUri);
            // Send request to upload file
            UploadFileBinary("c:\\temp\\test.jpg", UploadUrl, "PUT");

            //build URI to read barcode
            string strURI = "http://api.saaspose.com/v1.0/barcode/test.jpg/recognize?type=AllSupportedTypes";
            // Send the request to Saaspose server
            Stream responseStream = ProcessCommand(Sign(strURI), "GET");
            StreamReader reader = new StreamReader(responseStream);
            // Read the response
            string strJSON = reader.ReadToEnd();
            //Parse the json string to JObject
            JObject parsedJSON = JObject.Parse(strJSON);
            //Deserializes the JSON to a object. 
            RecognitionResponse barcodeRecognitionResponse = JsonConvert.DeserializeObject<RecognitionResponse>(parsedJSON.ToString());
            // Display the value and type of all the recognized barcodes
            foreach (RecognizedBarCode barcode in barcodeRecognitionResponse.Barcodes)
            {
                Console.WriteLine("Codetext: " + barcode.BarCodeValue + "\nType: " + barcode.BarCodeType);
            }

	    \\Here is the RecognitionResponse class
	    public class RecognitionResponse : BaseResponse
    	    {
        	public List<RecognizedBarCode> Barcodes { get; set; }
    	    }

	    \\Here is the RecognizedBarCode class	    
	    public class RecognizedBarCode
    	    {
        	public string BarCodeType { get; set; }
        	public string BarCodeValue { get; set; }
    	    }

	    \\Here is the BaseResponse class	    
	    public class BaseResponse
    	    {
        	public BaseResponse() { }
        	public string Code { get; set; }
        	public string Status { get; set; }
    	    }
This technical tip allows developers to read barcode from local image using Saaspose.BarCode REST API in your .NET applications. Some important steps for performing this task is to specify base product URI. This URI depends upon the version of the API you want to use in your application, build URI to upload file, enter app key and app SID, enter file name with full path, build remote URI to generate barcode, Sign remote URI, Send request and read barcode and Display the value and type of all the recognized barcodes.

Comments

Dan Rios replied on Fri, 2013/03/29 - 9:54pm