android - not correct take picture in custom camera activity -


i used custom camera .but open camera activity not take portrait mode .my code below.enter image description here

i used takebutton click :

btntakepicture.setonclicklistener(new onclicklistener() {              @override             public void onclick(view v) {                 // todo auto-generated method stub                 intent cameraact = new intent(getactivity(),                         cameraactivity.class);                 startactivityforresult(cameraact, 1);             }         }); 

cameraactivity:::

public class cameraactivity extends activity {      private camera mcamera;     private camerapreview mcamerapreview;     protected static final int media_type_image = 0;     static string filepath = "";     button takepicture;     static string base64string="";      @override     protected void oncreate(bundle savedinstancestate) {         // todo auto-generated method stub         super.oncreate(savedinstancestate);         setcontentview(r.layout.camera_preview);          mcamera = getcamerainstance();         mcamerapreview = new camerapreview(cameraactivity.this, mcamera);         framelayout preview = (framelayout) findviewbyid(r.id.camera_preview);         preview.addview(mcamerapreview);          takepicture = (button) findviewbyid(r.id.btntakepicture);         takepicture.setonclicklistener(new onclicklistener() {              @override             public void onclick(view v) {                 // todo auto-generated method stub                  mcamera.takepicture(null, null, mpicture);              }         });     }      private camera getcamerainstance() {         camera camera = null;         try {             camera = camera.open();         } catch (exception e) {             // cannot camera or not exist         }         return camera;     }      private static file getoutputmediafile() {         file mediastoragedir = new file(                 environment                         .getexternalstoragepublicdirectory(environment.directory_pictures),"mycameraapp");         if (!mediastoragedir.exists()) {             if (!mediastoragedir.mkdirs()) {                 log.d("mycameraapp", "failed create directory");                 return null;             }         }         // create media file name         string timestamp = new simpledateformat("yyyymmdd_hhmmss")                 .format(new date());          filepath = mediastoragedir.getpath() + file.separator + "img_"                 + timestamp + ".jpg";          log.v("log", " filepath " + filepath);          file mediafile;         mediafile = new file(mediastoragedir.getpath() + file.separator                 + "img_" + timestamp + ".jpg");          return mediafile;     }      picturecallback mpicture = new picturecallback() {         @override         public void onpicturetaken(byte[] data, camera camera) {             file picturefile = getoutputmediafile();             if (picturefile == null) {                 return;             }             try {                  fileoutputstream fos = new fileoutputstream(picturefile);                 fos.write(data);                 fos.close();                  intent returnintent = new intent();                 returnintent.putextra("data", data);                 setresult(result_ok, returnintent);                 finish();              } catch (filenotfoundexception e) {              } catch (ioexception e) {             }         }     };      public void onbackpressed() {         intent returnintent = new intent();         returnintent.putextra("path", filepath);         setresult(result_ok, returnintent);         finish();     }; } 

onactivity result in imageview set picture not set portrait mode. , code below ::

@override     public void onactivityresult(int requestcode, int resultcode, intent data) {         super.onactivityresult(requestcode, resultcode, data);          log.v("log", " data --> " + data.getbytearrayextra("data"));         if (requestcode == 1) {              if (data.hasextra("data")) {                  log.v("log", " request if ");                  bitmap b = bitmapfactory.decodebytearray(                         data.getbytearrayextra("data"), 0,                         data.getbytearrayextra("data").length);                    imgstorepicture.setimagebitmap(b);                 imgstorepicture.setrotation(90);                 /*imgstorepicture.setscaletype(scaletype.fit_xy);*/                  base64string = base64.encodebytes(data                         .getbytearrayextra("data"));                 log.v("log", "base64string " + base64string);                  }         }     } 


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -