First add reference to Esponce.QRCode.dll in your project. Choose an assembly according to your platform. Assemblies are organized in folders:
  • net35 - library for .NET 3.5 framework
  • silverlight - Silverlight for web
  • wp7 - Windows Phone 7 library

Generate a QR Code
using Esponce.QRCode

var client = new QRCodeClient();
var stream = client.Generate("Hello World"); //Returns PNG image

Generate blue QR Code in SVG format
var client = new QRCodeClient();
var stream = client.Generate("Hello World", "svg", 8, 4, null, QREncodeMode.Byte, QRErrorCorrection.M, Colors.Blue, Colors.White);

Customizing HTTP request
var client = new QRCodeClient();
client.UseSSL = true; //Use HTTPS
client.ApiKey = "d3m04u7h"; //Get API key at esponce.com
client.Format = ApiFormat.Json; //Transfer data in JSON format
client.ApplicationName = "MyFirstApplication"; //Appears in User-Agent string
...

Asynchronous request
//TODO: Show loading animation
var client = new QRCodeClient();
client.GenerateCompleted += (sender, e) =>
{
  //TODO: Hide loading animation
  using (var reader = new StringReader(e.Stream))
  {
	string svg = reader.ReadToEnd();
  }
};
client.GenerateAsync("Hello World", "eps");

Decoding a QR Code image
using System.IO;
using Esponce.QRCode;
...
var stream = File.OpenRead("sample.png");

var client = new QRCodeClient();
var result = client.Decode(stream);

Console.WriteLine(result.Content); //Read content from QR Code
Console.WriteLine(result.Dimension);
Console.WriteLine(result.Capacity);

Get list of campaigns and QR Codes
var client = new QRCodeClient();
client.UseSSL = true; //Use HTTPS
client.ApiKey = "d3m04u7h"; //Get API key at esponce.com

var client = new QRCodeClient();
var result = client.GetTrackList();

foreach (var campaign in result.Campaigns)
{
  //Do something with campaigns...
}

foreach (var qrcode in result.QRCodes)
{
  //Do something with QR Codes...
}

Export campaigns and QR Codes to CSV file
var client = new QRCodeClient();
client.UseSSL = true; //Use HTTPS
client.ApiKey = "d3m04u7h"; //Get API key at esponce.com

var stream = ExportTrackRecords(ExportFormat.CSV);
using (var reader = new StringReader(stream))
{
  string csv = reader.ReadToEnd();
  File.WriteAllText("output.csv", csv);
}

Last edited Oct 9, 2012 at 2:14 PM by Avivo, version 2

Comments

No comments yet.