camera.setParameters failed in android -


i have included camera functionality in application. have launched app in market. got error message 1 of users getting error while opening camera.

i have tested app on device on 2.1. error got user using nexus 1 run 2.2...here's logcat error i've received...

java.lang.runtimeexception: setparameters failed @ android.hardware.camera.native_setparameters(native method) @ android.hardware.camera.setparameters(camera.java:647) @ com.cameraapp.preview.surfacechanged(preview.java:67) @ android.view.surfaceview.updatewindow(surfaceview.java:538) @ android.view.surfaceview.dispatchdraw(surfaceview.java:339) @ android.view.viewgroup.drawchild(viewgroup.java:1638) @ android.view.viewgroup.dispatchdraw(viewgroup.java:1367) @ android.view.viewgroup.drawchild(viewgroup.java:1638) @ android.view.viewgroup.dispatchdraw(viewgroup.java:1367) @ android.view.viewgroup.drawchild(viewgroup.java:1638) @ android.view.viewgroup.dispatchdraw(viewgroup.java:1367) @ android.view.view.draw(view.java:6743) @ android.widget.framelayout.draw(framelayout.java:352) @ android.view.viewgroup.drawchild(viewgroup.java:1640) @ android.view.viewgroup.dispatchdraw(viewgroup.java:1367) @ android.view.view.draw(view.java:6743) @ android.widget.framelayout.draw(framelayout.java:352) @ com.android.internal.policy.impl.phonewindow$decorview.draw(phonewindow.java:1842) @ android.view.viewroot.draw(viewroot.java:1407) @ android.view.viewroot.performtraversals(viewroot.java:1163) @ android.view.viewroot.handlemessage(viewroot.java:1727) @ android.os.handler.dispatchmessage(handler.java:99) @ android.os.looper.loop(looper.java:123) @ android.app.activitythread.main(activitythread.java:4627) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:521) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:868) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:626) @ dalvik.system.nativestart.main(native method) 

i ran app on 2.2 emulator check it. worked fine. can please tell me why error occurring?

here class mentioned in comments:

class preview extends surfaceview implements surfaceholder.callback  {     private static final string tag = "preview";      surfaceholder mholder;     public camera camera;      preview(context context)      {         super(context);          // install surfaceholder.callback notified when         // underlying surface created , destroyed.         mholder = getholder();         mholder.addcallback(this);         mholder.settype(surfaceholder.surface_type_push_buffers);     }      public void surfacecreated(surfaceholder holder)      {         // surface has been created, acquire camera , tell         // draw.          camera = camera.open();         try {         camera.setpreviewdisplay(holder);         } catch (ioexception exception) {         camera.release();         camera = null;             // todo: add more exception handling logic here         }     }      public void surfacedestroyed(surfaceholder holder)      {         // surface destroyed when return, stop preview.         // because cameradevice object not shared resource, it's         // important release when activity paused.         camera.stoppreview();         camera.release();         camera = null;     }      public void surfacechanged(surfaceholder holder, int format, int w, int h)      {         // size known, set camera parameters , begin         // preview.          camera.parameters parameters = camera.getparameters();         parameters.setpreviewsize(w, h);         camera.setparameters(parameters);         camera.startpreview();     }      @override     public void draw(canvas canvas)      {         super.draw(canvas);         paint p= new paint(color.red);         log.d(tag,"draw");         canvas.drawtext("preview", canvas.getwidth()/2, canvas.getheight()/2, p );     } } 

it failing because not devices support arbitrary preview sizes. apparently can't rely on it. in surfacechanged method need this:

public void surfacechanged(surfaceholder holder, int format, int w, int h) {     camera.parameters parameters = camera.getparameters();     list<camera.size> previewsizes = parameters.getsupportedpreviewsizes();      // need choose appropriate previewsize app     camera.size previewsize = // .... select 1 of previewsizes here      parameters.setpreviewsize(previewsize.width, previewsize.height);     camera.setparameters(parameters);     camera.startpreview(); } 

you'll have figure out way scale don't lose aspect ratio etc.

for reference here android sdk doc.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -