Android: how to get the default camera settings for the built-in camera

I saw a lot of tutorial and information, but I could not find a single place, how to use the default settings for an existing camera application in any other camera application. I saw the sharpness of the image, and its focus is very good in the built-in camera application. Now I am creating my own application with my custom functions, but I still can’t make it clear and non-blurry ... I don’t want to use the Intent technique for the camera, because after that I need to do some image processing.

I used zooming, but weird zooming does not work properly ... as in the built-in camera application

here is my surface change code

public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { Log.e(TAG, "surfaceChanged"); // XXX stopPreview() will crash if preview is not running if (mPreviewRunning) { mCamera.stopPreview(); } Camera.Parameters params = mCamera.getParameters(); List<Camera.Size> sizes = params.getSupportedPreviewSizes(); mFrameWidth = w; mFrameHeight = h; // selecting optimal camera preview size { double minDiff = Double.MAX_VALUE; for (Camera.Size size : sizes) { if (Math.abs(size.height - h) < minDiff) { mFrameWidth = size.width; mFrameHeight = size.height; minDiff = Math.abs(size.height - h); } } } try { //params.set("rotation", 180); //params.set("orientation", "landscape"); //params.set("auto", "WHITE_BALANCE_AUTO");//WHITE_BALANCE_AUTO Display display = ((WindowManager)getSystemService(WINDOW_SERVICE)).getDefaultDisplay(); if(display.getRotation() == Surface.ROTATION_0) { params.setPreviewSize(mFrameHeight, mFrameWidth); mCamera.setDisplayOrientation(90); } if(display.getRotation() == Surface.ROTATION_90) { params.setPreviewSize(mFrameWidth, mFrameHeight); } if(display.getRotation() == Surface.ROTATION_180) { params.setPreviewSize(mFrameHeight, mFrameWidth); } if(display.getRotation() == Surface.ROTATION_270) { params.setPreviewSize(mFrameWidth, mFrameHeight); mCamera.setDisplayOrientation(180); } if(params.isZoomSupported()) { Log.e(TAG, params.getZoom()+"surfaceChanged camer zoom"+params.getMinExposureCompensation()); params.setZoom(params.getMaxZoom()); params.setExposureCompensation(1); // params.setColorEffect("none"); params.setWhiteBalance(params.WHITE_BALANCE_AUTO); params.setFocusMode(params.FOCUS_MODE_AUTO); params.setSceneMode(params.SCENE_MODE_ACTION); } params.set("auto", "FOCUS_MODE_AUTO"); params.setPreviewSize(mFrameWidth,mFrameHeight); mCamera.setParameters(params); mCamera.setPreviewDisplay(holder); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } mCamera.startPreview(); mPreviewRunning = true; } 

Please let me know how to make the camera preview the same as the built-in application.

+4
source share
2 answers

Do you mean full-screen viewing?

I am using this code:

 this.requestWindowFeature(Window.FEATURE_NO_TITLE); //no title getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); //no status bar, etc 

and this:

 setContentView(R.layout.main); addContentView(overlay, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); ((FrameLayout) findViewById(R.id.preview)).addView(preview); 

the first fragment sets the application to full screen mode and hides the title and status bar. the second snippet adds my overlay (extended view) to the main layout.

Here is my xml and java code: main.xml:

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <FrameLayout android:id="@+id/preview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /> </LinearLayout> 

Overlay.java:

 class Overlay extends View { String text = ""; String textBearing = "Bearing: "; public Overlay(Context context) { super(context); } @Override protected void onDraw(Canvas canvas) { Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.WHITE); paint.setTextSize(16); canvas.drawText(text, 20, 20, paint); canvas.drawText(textBearing, 20, 50, paint); super.onDraw(canvas); } } 

And my activity:

 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); //no title getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); //fullscreen overlay = new Overlay(this); setContentView(R.layout.main); addContentView(overlay, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); camera = getCameraInstance(); //camera.open(); preview = new Preview(this, camera); ((FrameLayout) findViewById(R.id.preview)).addView(preview); } 

Hope this helps

+2
source

I ran into the same problem with you. After reading the source code of the built-in camera application and comparing the focus processing of the built-in camera and my own camera, I realized that the problem is autofocus.

So try the following:

  mCamera.autoFocus(new Camera.AutoFocusCallback() { @Override public void onAutoFocus(boolean success, Camera camera) { mCamera.takePicture(null, null, mPicture); } }); 

which makes the result as sharp as the built-in camera. The docs are here .

0
source

Source: https://habr.com/ru/post/1397284/


All Articles