Q: Android Camera App preview after photo capture issue I made my preview activity class. 
Resolution choice i made good. While i am not taking photo everything looks good.
After calling mCamera.takePicture() i am getting my photo which have current resolution too. 
But just after calling mCamera.takePicture() preview freeze and appears for some time my photo but it has wrong sizes. 
Can i make this picture right?
Just found this question https://stackoverflow.com/questions/24134964/issue-with-camera-picture-taken-snapshot-using-surfaceview-in-android. It is just what i whant to solve.

A: First, get screen size of the device:
     public void getScreenSize() {

        Display display = getWindowManager().getDefaultDisplay();
        Point sizepoint = new Point();
        display.getSize(sizepoint);
        width = sizepoint.x;
        height = sizepoint.y;
    }

Then use these instructions to list the preview sizes supported by the device::
   Parameters p = Camera.getParameters();
   List<Size> size = p.getSupportedPreviewSizes();
   Size size_to_use  = getOptimalSize(size, width, height);

and finally set the preview sizes to the camera preview:

            p.setPreviewSize(size_to_use.width, size_to_use.height);
            myCamera.setParameters(p); 

Below, the getOptimalSize method (got from the net).
    private Size getOptimalSize(List<Size> sizes, int w, int h) {


        final double ASPECT_TOLERANCE = 0.2;        
        double targetRatio = (double) w / h;         
        if (sizes == null)             
            return null;          
        Size optimalSize = null;         
        double minDiff = Double.MAX_VALUE;          
        int targetHeight = h;          

        for (Size size : sizes) 
        {             

            double ratio = (double) size.width / size.height;            
            if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE)                
                continue;             
            if (Math.abs(size.height - targetHeight) < minDiff) 
            {                 
                optimalSize = size;                 
                minDiff = Math.abs(size.height - targetHeight);             
            }         
        }          
        // Cannot find the one match the aspect ratio, ignore the requirement     

        if (optimalSize == null)
        {
            minDiff = Double.MAX_VALUE;             
            for (Size size : sizes) {
                if (Math.abs(size.height - targetHeight) < minDiff)
                {
                    optimalSize = size;
                    minDiff = Math.abs(size.height - targetHeight); 
                }
            }
        }


        return optimalSize;     
    }


A: This might help you! Use this code for picture issue...
Size size = mSupportedPreviewSizes.get(previewSizeCounter);
parameters.setPictureSize(size.width, size.height);


A: If you have developed your own Camera API there are two things to take into consideration getSupportedPreviewSizes() and getSupportedPictureSizes() within camera parameters then choose the ones that are supported. it is up to you to choose and make necessary calculations to choose the right one.
