Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Captured camera image is looking blurry

Tags:

android

camera

My issue captured image is looking blurry in my application where as the image that is captured with the device camera component is looking good - something auto zoom effect is going once user click on capture button. can some one help me to achieve this scenario how and where should i apply.

here is the code:

public void surfaceChanged(SurfaceHolder holder, int format, int width,int height) {
    // Now that the size is known, set up the camera parameters and begin
    // the preview.
    Camera.Parameters parameters = camera.getParameters();
    Integer version = Integer.parseInt(Build.VERSION.SDK);
    if(version > Build.VERSION_CODES.ECLAIR_MR1)
    {
        Log.d(TAG, "------> version greater than eclari 2.1");
        List<Size> sizes = parameters.getSupportedPreviewSizes();
        Size optimalSize = getOptimalPreviewSize(sizes, width, height);
        parameters.setPreviewSize(optimalSize.width, optimalSize.height);
    }
    else
    {
        Log.d(TAG, "------> version less than eclari 2.1");
        parameters.setPreviewSize(ApplicationInitiator.screenW,ApplicationInitiator.screenH); 
    }

    List<String> focusModes = parameters.getSupportedFocusModes();
    if (focusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO))
    {
        parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
    }

    parameters.setJpegQuality(100);
    camera.setParameters(parameters);
    camera.startPreview();
}
like image 344
sakshi Avatar asked Jan 12 '12 16:01

sakshi


People also ask

Why does my camera lens look blurry?

Check to see if you can focus the lens manually to make sure the focus mechanism is not jammed. Also, check to see if the lens has a focus limiting switch. Some macro lenses and some of the longer zoom lenses have a switch that limits the range of focus.


1 Answers

Well, on your text you talk about capturing a image, but I don't see anything in your code about taking a picture, Anyway, if you want to obtain a focused photo, what you have to do is register a AutoFocusCallback to take a picture when focus is obtained:

Camera.AutoFocusCallback mAutoFocusCallback = new Camera.AutoFocusCallback() {
    @Override
    public void onAutoFocus(boolean success, Camera camera) {
        camera.takePicture(null, null, mPictureCallbackRaw);
    }
};

Camera.PictureCallback mPictureCallbackRaw = new Camera.PictureCallback() {  
    public void onPictureTaken(byte[] data, Camera c) { 
        // (...)            
    }  
};

public void takeFocusedPicture() {
    mCamera.autoFocus(mAutoFocusCallback);
}

.

like image 120
MobileCushion Avatar answered Oct 05 '22 17:10

MobileCushion