开发者

Get ZXing to work

I followed every instructions, wiki, getting started, guides, help, etc. I could find about ZXing project. After many many debugging, I finally manged to compile using ant core.jar, javame.jar, and javese.jar. I would like to integrate ZXing into my code, i.e., I wish to scan \read a barcode and handle its data.

I've imported as external jar each of the files mentioned above. Then I turned to https://code.google.com/p/zxing/wiki/DeveloperNotes to use the MultiFormatReader(). The BufferedImage class cannot be resolved. I tried whatever I know and I even tried android's Bitmap for a workaround, but it didn't help me either.

I know I c开发者_开发百科an use an intent to read\scan the barcode, but I wish to handle it myself and not to install a "3rd party" application.

Can anyone please help me understand how can I do so? Few lines of code will be appreciated.

And again, I only want to scan\read a barcode and analyze its data.


The shortest answer is that you should not use javase.jar in an Android app. It is code intended for JavaSE. Not all JavaSE classes are in Android. In particular Android does not have AWT classes like BufferedImage.

You only want to include core.jar in your project. Then write your Android app using it.


Jackson I too suggest you the way suggested by inazaruk.But if you are still having issues integrating that part of code (zxing-android).

  • Just download zxing-core
  • Import this core project to your eclipse
  • In your app's Eclipse build path add reference of zxing-core project so that it is not compiled by JVM but by Dalvik (just avoid using jar file because it is compiled with JVM) and simply use all the classes as suggested at https://code.google.com/p/zxing/wiki/DeveloperNotes

EDIT: As stated by Sean Owen android doesn't posses BufferedImage class.You need to import these classes & satisfy their dependency.

  • com.google.zxing.BinaryBitmap,
  • com.google.zxing.LuminanceSource,
  • com.google.zxing.MultiFormatReader,
  • com.google.zxing.Reader
  • com.google.zxing.Result
  • com.google.zxing.common.HybridBinarizer

Then you may use it like this

 Bitmap bMap = BitmapFactory.decodeStream(new FileInputStream(file));
 LuminanceSource source = new RGBLuminanceSource(bMap);
 BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(
                              source));
 Reader reader = new MultiFormatReader();

 Result result = reader.decode(bitmap);


Here is what I did for my experimental app:

  • Downloaded Android version of ZXing Barcode Scanner (here)
  • Converted this project into Android Library
  • Removed all the functionality I didn't need
  • Modified CaptureActivity the way I wanted, so its better integrated with my app.

I found this way was easier, because Android has some problems with uniform Camera support across different devices, and guys from ZXing already took care of it.


Hi Guys Actually I also stuck in this problem. But finally I run this project successfully. When we download zxing project and simply we import it but there are number for error comes because many file are missing.

Actually these files are distributed in whole projects. So if you search these files in Zxing-master you can find easily. Copy these files and simply copy in your projects as in my workspace it is "CaptureActivity". May be one problem is also come due to compilation error which due to Java Compiler (This project requires atleast Java 1.7 and Android OS 4.4).

Whatever i know when running this project I explained. Any query leave a comment.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜