Android Custom Camera Zoom Not Working -


i have seen several other questions on subject none seem solve problem. have custom camera app working fine, zoom buttons. code using sdk min 8 target 14:

@override         public void surfacechanged(surfaceholder holder, int format, int width,                 int height) {             if (ispreviewing){                  camera.stoppreview();              }              camera.parameters p = camera.getparameters();             p.setpreviewsize(sizes.get(0).width, sizes.get(0).height);             p.setcoloreffect(effect);               zoomcontrols = (zoomcontrols) findviewbyid(r.id.zoomcontrols);              if (p.iszoomsupported()) {                 maxzoomlevel = p.getmaxzoom();                 toast.maketext(picturetaker.this, string.valueof(maxzoomlevel),toast.length_long).show();                 zoomcontrols.setiszoominenabled(true);                 zoomcontrols.setiszoomoutenabled(true);                  zoomcontrols.setonzoominclicklistener(new onclicklistener() {                     public void onclick(view v) {                         if (currentzoomlevel < maxzoomlevel) {                             currentzoomlevel++;                             camera.startsmoothzoom(currentzoomlevel);                             //toast.maketext(picturetaker.this, string.valueof(currentzoomlevel),toast.length_long).show();                         }                     }                 });                  zoomcontrols.setonzoomoutclicklistener(new onclicklistener() {                     public void onclick(view v) {                         if (currentzoomlevel > 0) {                             currentzoomlevel--;                             camera.startsmoothzoom(currentzoomlevel);                         }                     }                 });             } else {                 zoomcontrols.setvisibility(view.gone);             }              camera.setparameters(p);               try {                 camera.setpreviewdisplay(holder);              } // end try             catch (ioexception e) {                 log.v(tag, e.tostring());             } // end catch              camera.startpreview(); // begin preview             ispreviewing = true;         } 

the setcoloreffect coming options menu , works perfectly. know iszoomsupported , getmaxzoom working because toast displays "59" when code runs, zoom buttons nothing. zoomcontrol xml

<zoomcontrols  android:id="@+id/zoomcontrols"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:layout_alignparentbottom="true"  android:layout_centerhorizontal="true"  android:layout_marginbottom="17dp"  android:baselinealigned="false"  android:gravity="center_horizontal"  android:orientation="horizontal" /> 

i have necessary permissions in manifest , no errors showing in logcat. not sure i'm doing wrong. added second toast report if currentzoomlevel being changed when button pressed , shows value getting incremented 1 each time. tried not using startsmoothzoom , setting zoom

p.setzoom(currentzoomlevel); or p.setzoomlevel(15);  

and neither 1 works either. phone, htc incredible have working zoom on native camera app. if comment out zoomcontrol parts of code, works fine , other features of custom camera work fine zoomcontrol code in there, doesn't zoom.

figured out , maybe can of other people have been having similar problems. smoothzoom. guess htc doesn't support this.

@override         public void surfacechanged(surfaceholder holder, int format, int width,                 int height) {             if (ispreviewing){                  camera.stoppreview();              }              p = camera.getparameters();             p.setpreviewsize(sizes.get(0).width, sizes.get(0).height);             p.setcoloreffect(effect);                 if (p.iszoomsupported() && p.issmoothzoomsupported()) {                 //most phones                 maxzoomlevel = p.getmaxzoom();                  zoomcontrols.setiszoominenabled(true);                 zoomcontrols.setiszoomoutenabled(true);                  zoomcontrols.setonzoominclicklistener(new onclicklistener() {                     public void onclick(view v) {                         if (currentzoomlevel < maxzoomlevel) {                             currentzoomlevel++;                             camera.startsmoothzoom(currentzoomlevel);                          }                     }                 });                  zoomcontrols.setonzoomoutclicklistener(new onclicklistener() {                     public void onclick(view v) {                         if (currentzoomlevel > 0) {                             currentzoomlevel--;                             camera.startsmoothzoom(currentzoomlevel);                         }                     }                 });             } else if (p.iszoomsupported() && !p.issmoothzoomsupported()){                 //stupid htc phones                 maxzoomlevel = p.getmaxzoom();                  zoomcontrols.setiszoominenabled(true);                 zoomcontrols.setiszoomoutenabled(true);                  zoomcontrols.setonzoominclicklistener(new onclicklistener() {                     public void onclick(view v) {                         if (currentzoomlevel < maxzoomlevel) {                             currentzoomlevel++;                             p.setzoom(currentzoomlevel);                             camera.setparameters(p);                          }                     }                 });                  zoomcontrols.setonzoomoutclicklistener(new onclicklistener() {                     public void onclick(view v) {                         if (currentzoomlevel > 0) {                             currentzoomlevel--;                             p.setzoom(currentzoomlevel);                             camera.setparameters(p);                         }                     }                 });             }else{                 //no zoom on phone                 zoomcontrols.setvisibility(view.gone);             }              camera.setparameters(p);               try {                 camera.setpreviewdisplay(holder);              } // end try             catch (ioexception e) {                 log.v(tag, e.tostring());             } // end catch              camera.startpreview(); // begin preview             ispreviewing = true;         } // end method surfacechanged 

this lets htc zoom in steps. key setting camera's parameters after each button click. set currentzoomlevel number want, based on maxzoomlevel, (my htc 59 droid 4 15), during clicks of zoomcontrols make device zoom in , out faster. might tidier way code this, should put checks in make sure maxzoomsize doesn't return null or something, it's working on multiple devices.


Comments

Popular posts from this blog

java - Cast from Object to List<String>: CastClassException -

How to set a border for android Imageview in Longpress? -

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -