Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android:摄像头表面视图模糊_Java_Android_Android Camera - Fatal编程技术网

Java Android:摄像头表面视图模糊

Java Android:摄像头表面视图模糊,java,android,android-camera,Java,Android,Android Camera,我正在使用android摄像头api构建自己的摄像头应用程序。我有一个可用的应用程序,但预览不如默认的相机应用程序清晰。为什么会这样?下面是我的代码 public class showCamera extends SurfaceView implements SurfaceHolder.Callback { private static final int PICTURE_SIZE_MAX_WIDTH =640; private static final int

我正在使用android摄像头api构建自己的摄像头应用程序。我有一个可用的应用程序,但预览不如默认的相机应用程序清晰。为什么会这样?下面是我的代码

public class showCamera  extends SurfaceView implements SurfaceHolder.Callback {

       private static final int PICTURE_SIZE_MAX_WIDTH =640;
        private static final int PREVIEW_SIZE_MAX_WIDTH = 640;
    //private Camera theCamera;
    private SurfaceHolder holdMe;
       private Camera theCamera;
        int h;
       int w;

    public showCamera (Context context,Camera camera,int w,int h)
    {
          super(context);
          theCamera = camera;
          holdMe = getHolder();
          holdMe.addCallback(this);
          this.h=h;
          this.w=w;




    }

    public showCamera(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width,
            int height) {
        // TODO Auto-generated method stub





    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
        // TODO Auto-generated method stub
        try   {
             theCamera.setPreviewDisplay(holder);
                //setDisplayOrientation(theCamera,90);
            if( (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT ))
            { theCamera.setDisplayOrientation(90); 
            }


            Camera.Parameters parameters = theCamera.getParameters();
            Log.d("     " , " THIS IS THE FLASH MODE = " + parameters.getFlashMode()) ;
             List<String> g=  parameters.getSupportedFocusModes();

             for(int j=0;j<g.size();j++)
             {
                 Log.d("     " , " THIS IS focus modes =" + g.get(j)) ;

             }

            Size bestPreviewSize = determineBestPreviewSize(parameters);
            Size bestPictureSize = determineBestPictureSize(parameters);

            parameters.setPreviewSize(bestPreviewSize.width, bestPreviewSize.height);
            parameters.setPictureSize(bestPictureSize.width, bestPictureSize.height);
            parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
            theCamera.setParameters(parameters);

             theCamera.startPreview(); 








          } catch (IOException e) {
          }


    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
         theCamera.stopPreview();
         theCamera.release();
        // TODO Auto-generated method stub

    }
     protected void setDisplayOrientation(Camera camera, int angle){
            Method downPolymorphic;
            try
            {
                downPolymorphic = camera.getClass().getMethod("setDisplayOrientation", new Class[] { int.class });
                if (downPolymorphic != null)
                    downPolymorphic.invoke(camera, new Object[] { angle });
            }
            catch (Exception e1)
            {
            }
        }

     private Size determineBestPreviewSize(Camera.Parameters parameters) {
            List<Size> sizes = parameters.getSupportedPreviewSizes();

            return determineBestSize(sizes, PREVIEW_SIZE_MAX_WIDTH);
        }

        private Size determineBestPictureSize(Camera.Parameters parameters) {
            List<Size> sizes = parameters.getSupportedPictureSizes();

            return determineBestSize(sizes, PICTURE_SIZE_MAX_WIDTH);
        }





     protected Size determineBestSize(List<Size> sizes, int widthThreshold) {
            Size bestSize = null;

            for (Size currentSize : sizes) {
                boolean isDesiredRatio = (currentSize.width / 4) == (currentSize.height / 3);
                boolean isBetterSize = (bestSize == null || currentSize.width > bestSize.width);
                boolean isInBounds = currentSize.width <= PICTURE_SIZE_MAX_WIDTH;

                if (isDesiredRatio && isInBounds && isBetterSize) {
                    bestSize = currentSize;
                }
            }

            if (bestSize == null) {


                return sizes.get(0);
            }

            return bestSize;
        }





     AutoFocusCallback autoFocusCallback = new AutoFocusCallback() {
          @Override
          public void onAutoFocus(boolean success, Camera camera) {
            Log.i("tag","this ran sdfgfhgjkldxbvnm,jhgfdkmn" ); 

          }
        };









}

如果你能给我指出正确的方向,那就太好了。

你有没有尝试过在showCamera类中增加这些值:

    private static final int PICTURE_SIZE_MAX_WIDTH = 640;
    private static final int PREVIEW_SIZE_MAX_WIDTH = 640;
    private static final int PICTURE_SIZE_MAX_WIDTH = 640;
    private static final int PREVIEW_SIZE_MAX_WIDTH = 640;