0

I am new to c#. currently I am trying to decode qr code via webcam, I have taken an example from the internet and re written it to try to understand the code. my question is How do I add using Zxing instead of using com.google.zxing?

I know that I should add a reference, but I try to add all the references I know but still it wouldnt allow me to add 'using Zxing'. it only allow 'using com.goggle.zxing' [ I use zxing.dll] as reference

Another problem is compiler error at var reader = new BarcodeReader(); I belief its related to the 'using Zxing" or unknown reference

I really need help on this matter. Kindly show me how to solve or where can I find the Zxing reference. thanks again.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Wee Leum
  • 31
  • 2
  • 7

3 Answers3

1

Simply put, you don't.

The library uses a namespace of com.google.zxing, so that's what you need to specify in the using directive. You don't get to change that namespace, unless you want to fetch the source code, change all the namespace declarations and rebuild. Why would you want to specify a different namespace in the using directive? What benefit do you think you'd achieve?

Of course you don't have to use a using directive at all. You could specify the full name of each type. For example:

com.google.zxing.MultiFormatReader reader = new com.google.zxing.MultiFormatReader();

But it would be much more sensible to use:

using com.google.zxing;

// Later in the code
MultiFormatReader reader = new MultiFormatReader();
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • sir, i took the example from this page "https://zxingnet.svn.codeplex.com/svn/trunk/Clients/AForgeDemo/AForgeDemoForm.cs" – Wee Leum Apr 28 '13 at 16:18
  • error 1 is Error = 1 The name 'LoadDevicesToCombobox' does not exist in the current context C:\Documents and Settings\WeeJim\My Documents\Visual Studio 2010\Projects\New Folder\AForgeDemo\AForgeDemo\Form1.cs 78 10 AForgeDemo – Wee Leum Apr 28 '13 at 16:19
  • error 2 is Error 2 The type or namespace name 'BarcodeReader' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\WeeJim\My Documents\Visual Studio 2010\Projects\New Folder\AForgeDemo\AForgeDemo\Form1.cs 159 27 AForgeDemo – Wee Leum Apr 28 '13 at 16:20
  • the only thing that i couldnt re produce is the using Zxing; can this be the reason for the error. kindly advise – Wee Leum Apr 28 '13 at 16:21
  • @WeeLeum: That's a different project! You can download the ZXing.Net library instead, but don't try to run examples from one project against the library from a different project. – Jon Skeet Apr 28 '13 at 16:21
  • sir , if based on this program "https://zxingnet.svn.codeplex.com/svn/trunk/Clients/AForgeDemo/AForgeDemoForm.cs" do u mean "DecodeBarcode" is a stand alone project which the programmer add into "AForgeDemo"? – Wee Leum Apr 28 '13 at 16:38
  • 2
    @WeeLeum: That code is a demo for `http://zxingnet.codeplex.com`, which is not the same project as `https://code.google.com/p/zxing/`. Decide which project you're using, and stick to it. – Jon Skeet Apr 28 '13 at 16:41
  • oh, thank you so much for highlighting it out.. looks like i was in the wrong direction all this while. thanks again sir. i appreciate it very much. – Wee Leum Apr 28 '13 at 16:46
1

This previous question should help you. Looks like com.google.zxing is the fully qualified namespace.

Try using that and checking if the objects and methods you require are present.

You could use and alias but why bother.

using zxing = com.google.zxing;
Community
  • 1
  • 1
Phil Murray
  • 6,396
  • 9
  • 45
  • 95
  • hai phil, thanks for replying. i appreciate it very much. sir, i took the example from this page "zxingnet.svn.codeplex.com/svn/trunk/Clients/AForgeDemo/. i have re type the whole program and face 2 error Error 1 is Error = 1 The name 'LoadDevicesToCombobox' does not exist in the current context C:\Documents and Settings\WeeJim\My Documents\Visual Studio 2010\Projects\New Folder\AForgeDemo\AForgeDemo\Form1.cs 78 10 AForgeDemo – Wee Leum Apr 28 '13 at 16:23
  • error 2 is Error 2 The type or namespace name 'BarcodeReader' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\WeeJim\My Documents\Visual Studio 2010\Projects\New Folder\AForgeDemo\AForgeDemo\Form1.cs 159 27 AForgeDemo – Wee Leum Apr 28 '13 at 16:23
  • he only thing that i couldnt re produce is the using Zxing; can this be the reason for the error. kindly advise – Wee Leum Apr 28 '13 at 16:24
  • Like Jon said in his post. Use the 'MultiFormatReader'. Lets face it Jon should know, he works for Google :-) – Phil Murray Apr 28 '13 at 16:34
  • I think I understand the problem now. I take it you are using the ZXing.Net library from CodePlex and not the com.google.zxing? Make sure you are using the correct DLL's from http://zxingnet.codeplex.com/ – Phil Murray Apr 28 '13 at 16:37
  • yes, mr phil. thanks for pointing out. now i know which direction i should go. thanks again. have a nice day. – Wee Leum Apr 28 '13 at 16:49
  • hai mr phil, can gv advice on this matter - http://stackoverflow.com/questions/16328757/need-help-on-button-to-switch-on-webcam-for-c-sharp-based-qr-code-project – Wee Leum May 02 '13 at 11:56
1

Just add this line for namespace.

using ZXing;

after installing from nugget package.