Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
Hi ,
I need to implement QRCode encoding and decoding in my Windows application(C#).
For this I started using zxing library.
It has some inbuild functions; but I don't know how to use it.
Could you please share some solution where in I can able to encode and decode by setting some parameters such as Errorcorrectionlevel,version, size etc.

Any help would be greatful.
Thanks in advance

-Vivek Deshmukh
Posted

Try this

http://windowqr.codeplex.com/SourceControl/list/changesets[ZXING Sample Project]

Decoding

C#
using com.google.zxing.qrcode;
using com.google.zxing;
using com.google.zxing.common;

public string Process(Bitmap bitmap)
{
  try
  {
    com.google.zxing.LuminanceSource source = new RGBLuminanceSource(bitmap, bitmap.Width, bitmap.Height);
    var binarizer = new HybridBinarizer(source);
    var binBitmap = new BinaryBitmap(binarizer);
    return reader.decode(binBitmap).Text;
  }
  catch
  {
    return string.Empty;
  }
}



Encoding
C#
QRCodeWriter writer = new QRCodeWriter();
Hashtable hints = new Hashtable();
            
            hints.Add(EncodeHintType.ERROR_CORRECTION, com.google.zxing.qrcode.decoder.ErrorCorrectionLevel.M);
            hints.Add("Version", "7");
            ByteMatrix byteIMGNew = writer.encode("Hello", BarcodeFormat.QR_CODE, 350, 350, hints);
            sbyte[][] imgNew = byteIMGNew.Array;
            Bitmap bmp1 = new Bitmap(byteIMGNew.Width, byteIMGNew.Height);
            Graphics g1 = Graphics.FromImage(bmp1);
            g1.Clear(Color.White);
            for (int i = 0; i <= imgNew.Length - 1; i++)
            {
                for (int j = 0; j <= imgNew[i].Length - 1; j++)
                {
                    if (imgNew[j][i] == 0)
                    {
                        g1.FillRectangle(Brushes.Black, i, j, 1, 1);
                    }
                    else
                    {
                        g1.FillRectangle(Brushes.White, i, j, 1, 1);
                    }
                }
            }
            bmp1.Save("D:\\QREncode.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
 
Share this answer
 
v4
Comments
Vivek Deshmukh 16-Aug-12 4:45am    
Hi dear,
I have downloaded this. It contains only classes.
But don't know how to interact with these.
razkp007 9-Sep-13 0:44am    
MY DECODE FUNCTION IS NOT WORKING . SEE CODE BELOW

using ZXing.Common;
using ZXing.QrCode;
using ZXing.QrCode.Internal;

private void Decode()
{
Bitmap bitmap = new Bitmap(@"D:\Project\QRCodes\myqrcode.png");
try
{
MemoryStream memoryStream = new MemoryStream();
bitmap.Save(memoryStream, ImageFormat.Bmp);

byte[] byteArray = memoryStream.GetBuffer();

ZXing.LuminanceSource source = new RGBLuminanceSource(byteArray, bitmap.Width, bitmap.Height);
var binarizer = new HybridBinarizer(source);
var binBitmap = new BinaryBitmap(binarizer);
QRCodeReader qrCodeReader = new QRCodeReader();

Result str = qrCodeReader.decode(binBitmap);

}
catch{ }

}
Renju Vinod 16-Aug-12 4:54am    
Hi Vivek,
In that link there is an option for "Latest Version" under that there is a link for download ,its a 2.9 MB file"windowqr-c5af0bb2fbba.zip"
hein thu 17-Sep-13 5:11am    
Hi all,
I using above encode solution of Renju Vinod. so thank but I have one problem. I want to know how to remove white border line. Please reply me.
Vivek Deshmukh 16-Aug-12 5:39am    
Hi Vinod,
It has a class named - com.google.zxing.qrcode.decoder.Decoder
and it contains one method Decode which require ByteMatrix parameter.
But my input is image. how to Convert Image to ByteMatrix ?

any Idea?
First,you need to integrate a QR Code encoder and QR Code decoder in c#.net,just then you can encode and decode QR Code in vb.net.
The best method for doing this is to leverage an existing QR code library compatible with the .net framework. A quick search reveals an open source project QRCode Library. The library supports both encoding and decoding qr codes. This should satisfy your condition of generating qr codes for Model Numbers and Product Numbers and then reading them.
 
Share this answer
 
Comments
Deepu S Nair 5-Feb-15 0:10am    
Answering old questions will attract downvoting.Its not a good idea

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900