Android: create barcode image and display in imageView -


my goal: generate pdf417 format 2d- barcode , display in imageview in application.

using zxing2.1 library's core.jar , j2se.jar.

following code trying create barcode , display in imageview.

imageview imageview = (imageview) findviewbyid(r.id.imageview);     try {          writer writer;         bitmatrix bitmatrix = null;         writer = new pdf417writer();         bitmatrix = writer.encode("123456789", barcodeformat.pdf_417, 580, 150);          bytearrayoutputstream bytearrayoutputstream = new bytearrayoutputstream();         matrixtoimagewriter.writetostream(bitmatrix, "png", bytearrayoutputstream);         inputstream decodedinput=new bytearrayinputstream(((bytearrayoutputstream) bytearrayoutputstream).tobytearray());         drawable d = bitmapdrawable.createfromstream(decodedinput, "src");         imageview.setimagedrawable(d);         system.out.println("pdf417 code generated.");     } catch (exception e) {      } 

when execute code, error:

07-01 08:42:13.148: error/dalvikvm(1508): not find class 'java.awt.image.bufferedimage', referenced method com.google.zxing.client.j2se.matrixtoimagewriter.tobufferedimage 07-01 08:42:13.178: error/androidruntime(1508): fatal exception: main     java.lang.noclassdeffounderror: java.awt.image.bufferedimage     @ com.google.zxing.client.j2se.matrixtoimagewriter.tobufferedimage(matrixtoimagewriter.java:54)     @ com.google.zxing.client.j2se.matrixtoimagewriter.writetostream(matrixtoimagewriter.java:99)     @ com.google.zxing.client.j2se.matrixtoimagewriter.writetostream(matrixtoimagewriter.java:91)     @ com.example.untitled.myactivity.oncreate(myactivity.java:35)     @ android.app.activity.performcreate(activity.java:5104)     @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1080)     @ android.app.activitythread.performlaunchactivity(activitythread.java:2144)     @ android.app.activitythread.handlelaunchactivity(activitythread.java:2230)     @ android.app.activitythread.access$600(activitythread.java:141)     @ android.app.activitythread$h.handlemessage(activitythread.java:1234)     @ android.os.handler.dispatchmessage(handler.java:99)     @ android.os.looper.loop(looper.java:137)     @ android.app.activitythread.main(activitythread.java:5039)     @ java.lang.reflect.method.invokenative(native method)     @ java.lang.reflect.method.invoke(method.java:511)     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793)     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560)     @ dalvik.system.nativestart.main(native method) 

the reason seems obvious. dont know how write image data stream bitmatrix.

kindly suggest solution. appreciate pointers, if any.

note: have gone through lot of stack overflow solutions , ones on web. of them around zxing integration , not cater specific problem. redirect me appropriate solution, in case hasn't lured attention.

also know elegant way of handling problem.

the whole java.awt.* framework isn't part of android sdk, including bufferedimage, , hence not supported emulator or physical devices. android has own implementation loading , rendering graphics.

referance here

as far solution problem refer here.. uses bitmap class aid in creating barcode..

hope helps...


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -