android - setParameters() failed on Zooming In using Zoom Controls -
i new android. working on camera app , using camera kit api. adding zoom functionality using camera api , implementing using zoom controls. when set parameters to parameter.setzoom(int value) java runtime exception setparameters failed. please help. have attached logs , code in snippet.
package com.lamaan.magmicrocam; import android.manifest; import android.content.context; import android.content.pm.packagemanager; import android.graphics.bitmap; import android.graphics.bitmapfactory; import android.graphics.imageformat; import android.graphics.surfacetexture; import android.hardware.camera; import android.hardware.camera2.cameraaccessexception; import android.hardware.camera2.cameracapturesession; import android.hardware.camera2.cameracharacteristics; import android.hardware.camera2.cameradevice; import android.hardware.camera2.cameramanager; import android.hardware.camera2.camerametadata; import android.hardware.camera2.capturerequest; import android.hardware.camera2.totalcaptureresult; import android.hardware.camera2.params.streamconfigurationmap; import android.media.image; import android.media.imagereader; import android.os.bundle; import android.os.environment; import android.os.handler; import android.os.handlerthread; import android.support.annotation.nonnull; import android.support.annotation.nullable; import android.support.v4.app.activitycompat; import android.support.v7.app.appcompatactivity; import android.util.log; import android.util.size; import android.util.sparseintarray; import android.view.surface; import android.view.textureview; import android.view.view; import android.widget.button; import android.widget.toast; import android.widget.zoomcontrols; import com.flurgle.camerakit.camera1; import com.flurgle.camerakit.camerakit; import com.flurgle.camerakit.cameralistener; import com.flurgle.camerakit.cameraview; import java.io.file; import java.io.filenotfoundexception; import java.io.fileoutputstream; import java.io.ioexception; import java.io.outputstream; import java.nio.bytebuffer; import java.util.arraylist; import java.util.arrays; import java.util.list; public class microscopeacitvity extends appcompatactivity implements view.onclicklistener { cameraview cameraview; button cameratakepic; button buttonflash; zoomcontrols zoomcontrols; camera mcamera; camera.parameters params; int currentzoomlevel = 0; float currentzoom; @override protected void oncreate(@nullable bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_microscope_acitvity); cameraview = (cameraview) findviewbyid(r.id.camera); cameratakepic = (button) findviewbyid(r.id.button_take_picture); cameratakepic.setonclicklistener(this); buttonflash = (button) findviewbyid(r.id.button_flash); buttonflash.setonclicklistener(this); zoomcontrols = (zoomcontrols) findviewbyid(r.id.microscope_zoom_control); cameraview.setcameralistener(new cameralistener() { @override public void onpicturetaken(byte[] picture) { super.onpicturetaken(picture); // create bitmap bitmap result = bitmapfactory.decodebytearray(picture, 0, picture.length); } }); // *************** zoom implementation starts here ******************** mcamera = camera.open(); if (mcamera.getparameters() != null){ params = mcamera.getparameters(); } if (params.iszoomsupported()) { final int maxzoomlevel = params.getmaxzoom(); log.i("max zoom ", "is " + maxzoomlevel); zoomcontrols.setiszoominenabled(true); zoomcontrols.setiszoomoutenabled(true); zoomcontrols.setonzoominclicklistener(new view.onclicklistener(){ public void onclick(view v){ if(currentzoomlevel < maxzoomlevel){ currentzoomlevel++; //mcamera.startsmoothzoom(currentzoomlevel); params.setzoom(currentzoomlevel); mcamera.setparameters(params); } } }); zoomcontrols.setonzoomoutclicklistener(new view.onclicklistener(){ public void onclick(view v){ if(currentzoomlevel > 0){ currentzoomlevel--; params.setzoom(currentzoomlevel); mcamera.setparameters(params); } } }); } else zoomcontrols.setvisibility(view.gone); // *************** zoom implementation ends here ******************** } @override protected void onresume() { super.onresume(); cameraview.start(); } @override protected void onpause() { cameraview.stop(); super.onpause(); } @override public void onclick(view v) { int id; id = v.getid(); if(id == r.id.button_take_picture){ cameraview.captureimage(); } if(id == r.id.button_flash){ cameraview.setflash(camerakit.constants.flash_on); } } }
error stack trace:
08-15 14:50:37.369 1766-1766/com.lamaan.magmicrocam e/androidruntime: fatal exception: main process: com.lamaan.magmicrocam, pid: 1766 java.lang.runtimeexception: setparameters failed @ android.hardware.camera.native_setparameters(native method) @ android.hardware.camera.setparameters(camera.java:1984) @ com.lamaan.magmicrocam.microscopeacitvity$2.onclick(microscopeacitvity.java:110) @ android.view.view.performclick(view.java:5721) @ android.view.view$performclick.run(view.java:22620) @ android.os.handler.handlecallback(handler.java:739) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:148) @ android.app.activitythread.main(activitythread.java:7406) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1230) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1120)
Comments
Post a Comment