1

I have this code for creating a camera preview to scan a QR code but doesn't work:

try {
            c = ((Class<? extends Controllo>) getIntent().getExtras().get("ctrl")).newInstance();
        } catch (Exception e) {
            Log.w("Error", e.toString());
            throw new RuntimeException(e.getMessage());
        }


        autoFocusHandler = new Handler();
        mCamera = getCameraInstance();

        Display display = getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);

        FrameLayout preview = (FrameLayout)findViewById(com.x720.qrscanner.R.id.cameraPreview);

        Camera.Parameters parameters = mCamera.getParameters();
        Boolean trovatoParam = false;
        int minValWidth = 0;
        int minValHeight = 0;
        for (Camera.Size previewSize: mCamera.getParameters().getSupportedPreviewSizes())
        {
            Log.e("SIZE", previewSize.width+" - " +previewSize.height);
            Log.e("SCHERMO", size.y+" - "+size.x);
            if(previewSize.width > minValWidth && previewSize.height > minValHeight && previewSize.width <= size.y && previewSize.height <= size.x) {
                parameters.setPreviewSize(previewSize.width, previewSize.height);
                Log.e("-------------SELEZIONO", previewSize.width+"");
                trovatoParam = true;
                minValWidth = previewSize.width;
                minValHeight = previewSize.height;
            }
        }

        if(trovatoParam == true)
            mCamera.setParameters(parameters);


        /* Instance barcode scanner */
        scanner = new ImageScanner();
        scanner.setConfig(0, Config.X_DENSITY, 3);
        scanner.setConfig(0, Config.Y_DENSITY, 3);

        scanner.setConfig(0, Config.ENABLE, 0);
        // only enable QRCODE
        scanner.setConfig(Symbol.QRCODE, Config.ENABLE, 1);

        mPreview = new CameraPreview(this, mCamera, previewCb, autoFocusCB);

        preview.addView(mPreview);

and this to get che camera:

public static Camera getCameraInstance(){
    Camera c = null;
    try {
        c = Camera.open();
    } catch (Exception e){
    }
    return c;
}

my problem is that camera preview doesn't fill al the screen but I have a big top border. I'm using a galaxy s8+. Sorry for bad English

issue image: enter image description here

Vaibhav Dhoke
  • 459
  • 6
  • 14
Alessandro Zago
  • 793
  • 3
  • 12
  • 33

1 Answers1

0

1) If your container is with width and height as match parent it will surely fill the screen. Check whether the framelayout is inside any other layout?

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </FrameLayout>

2) And if you are Using Relative layout outside Frame Layout please change it to Linear Layout

3) Or just try to use SurfaceView instead of FrameLayout.

Please check and let me know.. Best of Luck..

Varun Chandran
  • 647
  • 9
  • 23