Android custom camera setFocusAreas and setMeteringAreas not work on Samsung Devices -


maybe question duplicate question, others have not found solution. i'm trying write custom android camera , camera works fine on device(htc one).i tried different devices, , works in 1 of them. i'm having problems on samsung devices. not turn off autofocus feature on device. therefore, device can not change focus area. touch event.

@override public boolean ontouchevent(final motionevent event){      camera.parameters cameraparameters = camera.getparameters();     if (event.getaction() == motionevent.action_up){         focusareas.clear();         meteringareas.clear();         rect focusrect = calculatetaparea(event.getx(), event.gety(), 1f);         rect meteringrect = calculatetaparea(event.getx(), event.gety(), 1.5f);         focusareas.add(new camera.area(focusrect, 800));         meteringareas.add(new camera.area(meteringrect, 800));         cameraparameters.setfocusareas(focusareas);         cameraparameters.setmeteringareas(meteringareas);         cameraparameters.setfocusmode(camera.parameters.focus_mode_macro);         try{             camera.setparameters(cameraparameters);          } catch(exception e){             log.e("focus problem", e.tostring());             return false;         }          camera.autofocus(new camera.autofocuscallback() {                                @override             public void onautofocus(boolean success, camera camera) {                 camera.cancelautofocus();                 camera.parameters  params = camera.getparameters();                 if(params.getfocusmode() != camera.parameters.focus_mode_continuous_picture){                     params.setfocusmode(camera.parameters.focus_mode_continuous_picture);                     camera.setparameters(params);                 }             }         });          focussound = new mediaplayer();         showsquarefocus();         try {             assetfiledescriptor descriptor = this.getapplicationcontext().getassets()                     .openfd("focus.wav");             focussound.setdatasource(descriptor.getfiledescriptor(),                     descriptor.getstartoffset(), descriptor.getlength());             descriptor.close();             focussound.prepare();             focussound.setlooping(false);             focussound.start();             focussound.setvolume(10,10);             focussound.setoncompletionlistener(new oncompletionlistener(){                 public void oncompletion(mediaplayer mp){                     mp.release();                   }                 });         } catch (illegalargumentexception e) {             e.printstacktrace();         } catch (illegalstateexception e) {             e.printstacktrace();         } catch (ioexception e) {             e.printstacktrace();         }     }     return true; } 

maybe need code...

private rect calculatetaparea(float x, float y, float coefficient) {         int areasize = float.valueof(focus_area_size * coefficient).intvalue();         int left = clamp((int) x - areasize / 2, 0, width - areasize);         int top = clamp((int) y - areasize / 2, 0, height - areasize);         rectf rectf = new rectf(left, top, left + areasize, top + areasize);         matrix.maprect(rectf);         return new rect(math.round(rectf.left), math.round(rectf.top), math.round(rectf.right), math.round(rectf.bottom));     }      private int clamp(int x, int min, int max) {         if (x > max) {             return max;         }         if (x < min) {             return min;         }         return x;     } 

i've experienced same problem in samsung galaxy s3. solution i've found (even if dirty) set alternative focus mode before desired one.

private void setfocusmode(final camera camera, final string newfocusmode) {     // apply alternative focus mode      camera.parameters parameters = camera.getparameters();     final list<string> focusmodes = parameters.getsupportedfocusmodes();      if (focusmodes.contains(parameters.focus_mode_fixed) && newfocusmode.comparetoignorecase(parameters.focus_mode_fixed) == false)     {         parameters.setfocusmode(parameters.focus_mode_fixed);     }     else if (focusmodes.contains(parameters.focus_mode_infinity) && newfocusmode.comparetoignorecase(parameters.focus_mode_infinity) == false)     {         parameters.setfocusmode(parameters.focus_mode_infinity);     }     else if (focusmodes.contains(parameters.focus_mode_macro) && newfocusmode.comparetoignorecase(parameters.focus_mode_macro) == false)     {         parameters.setfocusmode(parameters.focus_mode_macro);     }     else if (focusmodes.contains(parameters.focus_mode_auto) && newfocusmode.comparetoignorecase(parameters.focus_mode_auto) == false)     {         parameters.setfocusmode(parameters.focus_mode_auto);     }      camera.setparameters(parameters);      // apply desired focus mode      parameters = camera.getparameters();     parameters.setfocusmode(newfocusmode);     camera.setparameters(parameters); } 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -