Returning (android.hardware.Camera) in landscape mode -


i building app contains video capture custom camera surface view. works fine in portrait mode, when change landscape mode camera preview goes blank screen.

here's code i'm using:

@override public void onconfigurationchanged(configuration newconfig) {     super.onconfigurationchanged(newconfig);     setcontentview(r.layout.camera_activity);          camera1 = camera.open(camid);         try {             camera1.setpreviewdisplay(surfaceholder);             camera1.startpreview();         } catch (ioexception e) {             e.printstacktrace();         }  } 

in configurationchanged function i'm not getting camera1 object.

how can solve this?

you need override onsaveinstancestate(bundle savedinstancestate) , write application state values want change bundle parameter this:

you can saved instance of each variable this

@override public void onsaveinstancestate(bundle savedinstancestate) {   super.onsaveinstancestate(savedinstancestate);   // save ui state changes savedinstancestate.   // bundle passed oncreate if process   // killed , restarted.   savedinstancestate.putboolean("myboolean", false);   savedinstancestate.putdouble("mydouble", 1.121);   savedinstancestate.putint("myint", 0);   savedinstancestate.putstring("mystring", "your string");   // etc. } 

and changes can retrive

@override public void onrestoreinstancestate(bundle savedinstancestate) {   super.onrestoreinstancestate(savedinstancestate);   // restore ui state savedinstancestate.   // bundle has been passed oncreate.   boolean myboolean = savedinstancestate.getboolean("myboolean");   double mydouble = savedinstancestate.getdouble("mydouble");   int myint = savedinstancestate.getint("myint");   string mystring = savedinstancestate.getstring("mystring"); } 

hope .cheers!

update:

if (getresources().getconfiguration().orientation == configuration.orientation_portrait)         {                p.set("orientation", "portrait");             p.set("rotation",90);         }         if (getresources().getconfiguration().orientation == configuration.orientation_landscape)         {                                            p.set("orientation", "landscape");                       p.set("rotation", 90);         } 

and set property this:

camera.parameters parameters = camera.getparameters(); parameters.set("orientation", "portrait"); camera.setparameters(parameters); 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -