Over a million developers have joined DZone.

Read & Recognize Barcode from External Image URL in Java Applications

DZone's Guide to

Read & Recognize Barcode from External Image URL in Java Applications

· ·
Free Resource

This technical tip allows developers to read barcode from external image URL  using Saaspose.BarCode REST API in your Java applications. Some important steps for performing this task is to build URI for reading barcode, sending the request to Saaspose server, parse and Deserializes the JSON to an object and display the value and type of all the recognized barcodes.

//build URI to read barcode
	    //type:  Codabar, Code11, Code128 and Code39Extended etc.
            String strURI = "http://api.saaspose.com/v1.0/barcode/recognize?type=QR&url=http://upload.wikimedia.org/wikipedia/commons/c/ce/WikiQRCode.png";
            // Send the request to Saaspose server
            InputStream responseStream = ProcessCommand(Sign(strURI), "POST");
            // Read the response
            String strJSON = StreamToString(responseStream);
            //Parse and Deserializes the JSON to a object. 
            RecognitionResponse barcodeRecognitionResponse = gson.fromJson(strJSON,RecognitionResponse.class);
   barcodes = barcodeRecognitionResponse.getBarcodes();
            // Display the value and type of all the recognized barcodes
	    for (RecognizedBarCode barcode : barcodes)
	        System.out.println("Codetext: " + barcode.BarcodeValue() + "\nType: " + barcode.getBarcodeType());

	    \\Here is the RecognitionResponse class
	    public class RecognitionResponse extends BaseResponse
	        private List
    Barcodes ;
	        public List
     getBarcodes(){return Barcodes;}

	    \\Here is the RecognizedBarCode class	    
	    public class RecognizedBarCode
	        private String BarcodeType ;
	        private String BarcodeValue;
	        public String getBarcodeType(){return BarcodeType;}
	        public String BarcodeValue(){return BarcodeValue;}

	    \\Here is the BaseResponse class	    
	    public class BaseResponse 
	        public BaseResponse() { }
	        private String Code;
	        private String Status;
	        public String getCode(){return Code;}
	        public String getStatus(){return Status;}
	        public void  setCode(String temCode){ Code=temCode;}
	        public void setStatus(String temStatus){ Status=temStatus;}


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}