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.
Sample Code for Reading barcode from local image
//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");
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);
}
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; }
}
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; }
}
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; }
}
public class BaseResponse
{
public BaseResponse() { }
public string Code { get; set; }
public string Status { get; set; }
}
Overview: Saaspose.Barcode
Saaspose.Barcode is a cloud based REST API that helps developers to generate new barcode images from scratch, recognize barcodes from images, specify barcode text attributes, set barcode image characteristics like width, height, border style, output format etc. Developers can create barcode using more than 40 symbologies like (1D) EAN13, EAN8, UPCA, UPCE barcode, MSI & Code11 (2D) like PDF417, DataMatrix, Aztec, QR, Italian Post 25 & postal types like Postnet, Planet, USPS OneCode & many more.
More about Saaspose.BarCode
- Homepage of Saaspose.BarCode
- Saaspose.BarCode REST Live Examples
- More Technical Tips by Saaspose.BarCode
- Ask technical questions/queries from Saaspose Support Team
Contact Information
Aspose Pty Ltd, Suite 163,
79 Longueville Road
Lane Cove, NSW, 2066
Australia
Saaspose - Your File Format Experts 2.0
sales@aspose.com
Phone: 1.214.329.1520
Fax: 866.810.9465
79 Longueville Road
Lane Cove, NSW, 2066
Australia
Saaspose - Your File Format Experts 2.0
sales@aspose.com
Phone: 1.214.329.1520
Fax: 866.810.9465
No comments:
Post a Comment