android - How to check the image from the camera is stored in the device is in a proper format to set it in a image view? -
in application use camera take picture , store in specified folder,then image folder , set image view.
what facing image in folder being converting proper jpeg format,which takes few sec form image format(this problem occurs when set image in image view after closing camera).is there way(or condition) check whether image in proper format. or there way on click of camera tick button can use handler few seconds set image image view.!!!
what i've done show image view photo camera , store this:
@override protected void onactivityresult(int requestcode, int resultcode, intent data) { if (resultcode == result_ok) { switch(requestcode) { case request_take_photo: if (data != null) { bundle extras = data.getextras(); bitmap imagebitmap = (bitmap) extras.get("data"); // guardamos la imagen // create file photo should go file photofile = null; try { photofile = createimagefile(); // continue if file created if (photofile != null && isexternalstoragereadable() && isexternalstoragewritable()) { fileoutputstream fout = new fileoutputstream(photofile); imagebitmap.compress(bitmap.compressformat.png, 100, fout); fout.close(); } } catch (ioexception ex) { // error occurred while creating file log.e(tag, "error creando el fichero para guardado de imagen del alumno"); } imagenalumno.setimagebitmap(imagebitmap); } else { log.e(tag, "devulción de foto null"); } break; } } }
the methods used these:
private file createimagefile() throws ioexception { // create image file name string imagefilename = "filename"; file storagedir = new file( environment.getexternalstoragepublicdirectory( environment.directory_documents) + file.separator + "folder"); file image = file.createtempfile( imagefilename, /* prefix */ ".jpg", /* suffix */ storagedir /* directory */ ); return image; } public boolean isexternalstoragewritable() { string state = environment.getexternalstoragestate(); if (environment.media_mounted.equals(state)) { return true; } return false; } public boolean isexternalstoragereadable() { string state = environment.getexternalstoragestate(); if (environment.media_mounted.equals(state) || environment.media_mounted_read_only.equals(state)) { return true; } return false; }
notice use bitmap returned camera show image , can store image want. let me know if helps cos i'm not sure if solve asking for.
Comments
Post a Comment