android - Call Bitmap inside onPictureTaken -


how can call bitmap inside onpicturetaken method ?. image not storing in gallery until , unless restart phone

please in re-arranging code.

public static int getorientation(context context,uri photouri){     cursor cursor = context.getcontentresolver().query(photouri,new string[] {mediastore.images.imagecolumns.orientation},null,null,null);     if(cursor.getcount()!=1){         return -1;     }     cursor.movetofirst();     return cursor.getint(0);  } 

getcorrectlyorientatedimage() never used. please me in can call function.

public static bitmap getcorrectlyorientatedimage(context context, uri photouri)throws ioexception{     inputstream is=context.getcontentresolver().openinputstream(photouri);     bitmapfactory.options dbo = new bitmapfactory.options();     dbo.injustdecodebounds = true;     bitmapfactory.decodestream(is,null,dbo);     is.close();      int rotatedwidth,rotatedheight;     int orientation = getorientation(context,photouri);      if(orientation == 90 || orientation ==270){         rotatedwidth=dbo.outheight;         rotatedheight=dbo.outwidth;     }else{         rotatedwidth=dbo.outwidth;         rotatedheight=dbo.outheight;     }      bitmap srcbitmap;     = context.getcontentresolver().openinputstream(photouri);     if(rotatedwidth > max_image_dimension || rotatedheight > max_image_dimension ){         float widthratio = ((float) rotatedwidth) / ((float) max_image_dimension);         float heightratio = ((float) rotatedheight) / ((float) max_image_dimension);         float maxratio = math.max(widthratio,heightratio);          bitmapfactory.options options = new bitmapfactory.options();         options.insamplesize = (int) maxratio;         srcbitmap = bitmapfactory.decodestream(is, null, options);     }else{         srcbitmap = bitmapfactory.decodestream(is);     }     is.close();      if(orientation > 0){         matrix matrix = new matrix();         matrix.postrotate(orientation);          srcbitmap = bitmap.createbitmap(srcbitmap,0,0,srcbitmap.getwidth(),srcbitmap.getheight(),matrix,true);     }     return srcbitmap; }   private picturecallback mpicture = new picturecallback() {       public void onpicturetaken(byte[] data, camera camera) {          file picturefile = getoutputmediafile(media_type_image);         log.d("onpicturetaken", "file assigned picturefile");         if (picturefile == null) {             log.d(debug_tag, " error creating media file, check storage permissions:");             return;         }        try {             bitmap bitmap=getcorrectlyorientatedimage()             fileoutputstream fos = new fileoutputstream(picturefile);             fos.write(data);             fos.close();             file mediastoragedir = new file(environment.getexternalstoragepublicdirectory(environment.directory_pictures), "selfie");             string path = mediastoragedir.getpath() + file.separator + "img_some_name.jpg";             scamera.this.sendbroadcast(new intent(intent.action_media_scanner_scan_file, uri.parse("file://" + path)));         } catch (filenotfoundexception e) {             log.d("dg_debug", "file not found: " + e.getmessage());         } catch (ioexception e) {             log.d("dg_debug", "error accessing file: " + e.getmessage());         }      }  }; 

image not storing in sdcard untill reboot phone , image stored stored in wrong direction. if photo taken in portrait , image stored in landscape . how can store image in correct orientation.

private static file getoutputmediafile(int type){     file mediastoragedir = new file(environment.getexternalstoragepublicdirectory(environment.directory_pictures),"selfie");     if(!mediastoragedir.exists()){         if(!mediastoragedir.mkdir()){             log.d(debug_tag,"filed create directory");             return null;         }     }     string timestamp = new simpledateformat("yyyymmdd_hhmmss").format(new date());     file mediafile;     if (type == media_type_image){         mediafile = new file(mediastoragedir.getpath() + file.separator +                 "img_"+ timestamp + ".jpg");     } else {         return null;     }      return mediafile; } 

i know question little old, in case faces same issue, solution save image in background thread shown in this github link.

private picturecallback mpicture = new picturecallback() {      public void onpicturetaken(byte[] data, camera camera) {         new saveimagetask().execute(data);     }  };   private class saveimagetask extends asynctask<byte[], void, void> {      @override     protected void doinbackground(byte[]... data) {          file picturefile = getoutputmediafile(media_type_image);         log.d("onpicturetaken", "file assigned picturefile");         if (picturefile == null) {             log.d(debug_tag, " error creating media file, check storage permissions:");             return null;         }         try {             bitmap bitmap=getcorrectlyorientatedimage()             fileoutputstream fos = new fileoutputstream(picturefile);             fos.write(data);             fos.close();             file mediastoragedir = new file(environment.getexternalstoragepublicdirectory(environment.directory_pictures), "selfie");             string path = mediastoragedir.getpath() + file.separator + "img_some_name.jpg";             scamera.this.sendbroadcast(new intent(intent.action_media_scanner_scan_file, uri.parse("file://" + path)));         } catch (filenotfoundexception e) {             log.d("dg_debug", "file not found: " + e.getmessage());         } catch (ioexception e) {             log.d("dg_debug", "error accessing file: " + e.getmessage());         }      }  } 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -