android - Can't configure Camera2 API for a preview -


i need set preview camera, use scan qr code, using camera2 api. problem configure camera. code:

//setting preview surface layout file  <?xml version="1.0" encoding="utf-8"?> 

<surfaceview     android:layout_width="250dp"     android:layout_height="250dp"     android:id="@+id/surfaceview"     android:layout_gravity="center"     android:layout_centervertical="true"     android:layout_centerhorizontal="true" />  <textview     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:textappearance="?android:attr/textappearancemedium"     android:text="@string/scanqr"     android:id="@+id/textview"     android:gravity="center_horizontal"     android:layout_above="@+id/surfaceview"     android:layout_centerhorizontal="true" /> 

in code:

//after cameradevice... cameracharacteristics caracteristicas=cmanager.getcameracharacteristics(chosencam); streamconfigurationmap map = caracteristicas.get(cameracharacteristics.scaler_stream_configuration_map); size[] mpreviewsize = map.getoutputsizes(what put here); surfaceviewcamera = (surfaceview)dcamera.findviewbyid(r.id.surfaceview);        surfaceviewcamera.getholder().addcallback(this);  mpreviewrequestbuilder= cdevice.createcapturerequest(cameradevice.template_preview); surface surface=surfaceviewcamera.getholder().getsurface(); mpreviewrequestbuilder.addtarget(surface); cdevice.createcapturesession(arrays.aslist(surface), new cameracapturesession.statecallback(){...onconfigured, oncapturefailed , onconfigurefailed methods...} 

my problem don't know how configure camera, enters onconfigurationfailed method. that? knows specific tutorial topic?

thank you.

edit:

no luck. code looks this:

cameracharacteristics caracteristicas=cmanager.getcameracharacteristics(chosencam); streamconfigurationmap map = caracteristicas.get(cameracharacteristics.scaler_stream_configuration_map); size[] mpreviewsize = map.getoutputsizes(imageformat.jpeg); ireader=imagereader.newinstance(mpreviewsize[0].getwidth(), mpreviewsize[0].getheight(),imageformat.jpeg, 1); ireader.setonimageavailablelistener(new imagereader.onimageavailablelistener() {        @override        public void onimageavailable(imagereader reader) {                 log.i("tag", "we have image. yay!");                         }                     }, backgroundhandler); 

i don't receive exception, goes onconfigurationfailed, , says:

06-29 08:20:50.377    1410-1410/my.package e/legacy-cameradevice-jni﹕ legacycameradevice_nativedetectsurfacedimens: not retrieve native window surface. 06-29 08:20:50.388    1410-1410/my.package w/cameradevice-jv-0﹕ stream configuration failed 06-29 08:20:51.283    1410-1410/my.package e/cameracapturesession﹕ session 0: failed create capture session; configuration failed 06-29 08:21:12.179    1410-1410/my.package i/choreographer﹕ skipped 26759 frames!  application may doing work on main thread. 06-29 08:21:13.424    1410-1416/my.package w/art﹕ suspending threads took: 13.264ms 06-29 08:21:20.458    1410-1416/my.package w/art﹕ suspending threads took: 12.178ms 06-29 08:21:24.481    1410-1416/my.package w/art﹕ suspending threads took: 7.194ms 06-29 08:21:28.496    1410-1416/my.package w/art﹕ suspending threads took: 5.281ms 06-29 08:21:34.031    1410-1416/my.package w/art﹕ suspending threads took: 7.869ms 06-29 08:21:39.923    1410-1477/my.package i/openglrenderer﹕ initialized egl, version 1.4 06-29 08:21:39.989    1410-1477/my.package w/egl_emulation﹕ eglsurfaceattrib not implemented 06-29 08:21:39.989    1410-1477/my.package w/openglrenderer﹕ failed set egl_swap_behavior on surface 0xb4ba9b60, error=egl_success 

pd: im debugging emulator, in case helps


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -