Android SurfaceView Preview Blurry -
i have quick question. i'm using android's surfaceview take picture , save it. however, preview size , picture quality both terrible; in, blurry. there's no sharpness picture quality @ all.
here's initialize surfaceview:
camera.setdisplayorientation(90); parameters parameters = camera.getparameters(); parameters.setwhitebalance(camera.parameters.white_balance_auto); parameters.setexposurecompensation(0); parameters.setpictureformat(imageformat.jpeg); parameters.setjpegquality(100); camera.size picsize = getoptimalpreviewsize(parameters.getsupportedpreviewsizes(), getresources().getdisplaymetrics().widthpixels, getresources().getdisplaymetrics().heightpixels); parameters.setpicturesize(picsize.width, picsize.height); parameters.setpreviewsize(picsize.width, picsize.height); camera.setparameters(parameters); camera.setpreviewdisplay(holder); camera.startpreview();
the getoptimalpreviewsize() returns best size available parameters.getsupportedpreviewsizes(). size returns 1280x720, best size phone support. however, surfaceview still blurry. there wrong i'm doing, or there way optimize surfaceview? thanks.
there 2 reason why image , preview may appear blurry
1) way settings picture size , preview size wrong. have query supported sizes , decide best size , set size list have got. cannot give arbit values. check sample app implementation details - https://github.com/josnidhin/android-camera-example
2) have put camera in auto foucs mode focus automatically. (better implement touch focus proper ui). once camera starts set below
private void setcamfocusmode(){ if(null == mcamera) { return; } /* set auto focus */ parameters parameters = mcamera.getparameters(); list<string> focusmodes = parameters.getsupportedfocusmodes(); if(focusmodes.contains(camera.parameters.focus_mode_continuous_picture)){ parameters.setfocusmode(camera.parameters.focus_mode_continuous_picture); } else if(focusmodes.contains(camera.parameters.focus_mode_auto)){ parameters.setfocusmode(camera.parameters.focus_mode_auto); } mcamera.setparameters(parameters); }
make sure have proper permission in manifest
hope helps
regards, shrish
Comments
Post a Comment