问题:
好吧,我已经看到了很多如何做到这一点的例子,但是在这个库(Zxing 2.1)中似乎没有一个工作。我想将字符串编码为 QRCode 并让位图显示在 Imageview 中。
问题:
我应该使用旧版本吗?有人有 Zxing library 2.1 的工作示例吗?
我试过的:
String contents = uniqueID;
BarcodeFormat barcodeFormat = BarcodeFormat.QR_CODE;
int width = 300;
int height = 300;
MultiFormatWriter barcodeWriter = new MultiFormatWriter();
try {
BitMatrix matrix = barcodeWriter.encode(contents, barcodeFormat, width, height);
} catch (WriterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
得到了这个:
01-05 13:02:10.701: E/AndroidRuntime(1375): FATAL EXCEPTION: main
01-05 13:02:10.701: E/AndroidRuntime(1375): java.lang.NoClassDefFoundError: com.google.zxing.BarcodeFormat
01-05 13:02:10.701: E/AndroidRuntime(1375): at br.com.example.nightid.slidingsubmenu.IDcard.onCreate(IDcard.java:75)
01-05 13:02:10.701: E/AndroidRuntime(1375): at android.app.Activity.performCreate(Activity.java:4465)
01-05 13:02:10.701: E/AndroidRuntime(1375): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
01-05 13:02:10.701: E/AndroidRuntime(1375): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
01-05 13:02:10.701: E/AndroidRuntime(1375): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
01-05 13:02:10.701: E/AndroidRuntime(1375): at android.app.ActivityThread.access$600(ActivityThread.java:123)
01-05 13:02:10.701: E/AndroidRuntime(1375): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
01-05 13:02:10.701: E/AndroidRuntime(1375): at android.os.Handler.dispatchMessage(Handler.java:99)
01-05 13:02:10.701: E/AndroidRuntime(1375): at android.os.Looper.loop(Looper.java:137)
01-05 13:02:10.701: E/AndroidRuntime(1375): at android.app.ActivityThread.main(ActivityThread.java:4424)
01-05 13:02:10.701: E/AndroidRuntime(1375): at java.lang.reflect.Method.invokeNative(Native Method)
01-05 13:02:10.701: E/AndroidRuntime(1375): at java.lang.reflect.Method.invoke(Method.java:511)
01-05 13:02:10.701: E/AndroidRuntime(1375): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-05 13:02:10.701: E/AndroidRuntime(1375): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-05 13:02:10.701: E/AndroidRuntime(1375): at dalvik.system.NativeStart.main(Native Method)
对不起,如果我犯了一个大错误,第一次使用这个库。