i have couple of days trying capture photo in android, idea upload file ftp once captured image. have class extends surfaceview, when becomes visible, plays image of rear camera of device, here right. clicking on image of camera, keep image in jpeg format.
i've tried dozens of solutions but, right jpeg totally black. think im in right way, missing.
here code use in onclick event on custom class:
try { //create bitmap screen capture bitmap bitmap; this.setdrawingcacheenabled(true); //freezes image mcamera.stoppreview(); bitmap = bitmap.createbitmap(getdrawingcache(), 0, 0, this.getlayoutparams().width, this.getlayoutparams().height); this.setdrawingcacheenabled(false); //create temp file file = file.createtempfile("prueba", ".jpg", environment.getexternalstoragepublicdirectory(environment.directory_pictures)); //copy bitmap content file fileoutputstream fos = new fileoutputstream(file); bitmap.compress(compressformat.jpeg, 60, fos); fos.flush(); fos.close(); //free camera mcamera.release(); mcamera = null; }catch(exception e){ e.printstacktrace(); } mcamera android.hardware.camera, specific size selected , copied width , height this.layoutparams fit, in surfacecreated() method.
hope can me indication.
thank much.
thank help.
i've taken solution. liked first option, because camera integrated application , easier control rotation of image , resolution of preview.
by now, image taked in intent resized , loaded object imagepreview (that imageview). here solution:
call camera intent:
intent intent = new intent(android.provider.mediastore.action_image_capture); if (getpackagemanager().queryintentactivities(intent, packagemanager.match_default_only).size()>0) { pathimagen = android.net.uri.fromfile(file.createtempfile("prueba"+system.currenttimemillis(), ".jpg", environment.getexternalstoragepublicdirectory(environment.directory_pictures))); intent.putextra(android.provider.mediastore.extra_output, pathimagen); startactivityforresult(intent, 94010); } get image file , resize:
public void onactivityresult(int requestcode, int resultcode, intent data) { switch (requestcode) { case 94010: if (resultcode == activity.result_ok) { bitmap bmp = null; try { //obtenemos las dimensiones de la imagen (no se carga la imagen completa) contentresolver cr = getcontentresolver(); cr.notifychange(pathimagen, null); bitmapfactory.options options = new bitmapfactory.options(); options.inpreferredconfig = config.rgb_565; options.injustdecodebounds = true; bitmapfactory.decodefile(pathimagen.getencodedpath(), options); //bmp = android.provider.mediastore.images.media.getbitmap(cr, pathimagen); system.out.println("tamaño imagen: "+options.outwidth+"x"+options.outheight); //bitmap bmp = (bitmap) data.getextras().get("data"); int anchofinal = 480; int altofinal = (options.outheight*480)/options.outwidth; options.injustdecodebounds = false; bmp = bitmap.createscaledbitmap(bitmapfactory.decodefile(pathimagen.getencodedpath(), options), anchofinal, altofinal, false); system.out.println("tamaño imagen despues escalar: "+bmp.getwidth()+"x"+bmp.getheight()); this.imagepreview.setvisibility(view.visible); this.imagepreview.getlayoutparams().width = bmp.getwidth(); this.imagepreview.getlayoutparams().height = bmp.getheight(); this.imagepreview.setimagebitmap(bmp); this.popupeditobject.setvisibility(view.visible); } catch (exception e) { e.printstacktrace(); } } } } the problem image comes resolution of 3264x1968. no matter has taken horizontally or vertically o_o i'll see if intent returns information that.
i hope helps more people , have seen many forums no answers works.
i appreciate feedback refine code.
thanks again!
Comments
Post a Comment