Ask Your Question
2

JavaCameraView preview not fullscreen

asked 2015-02-26 02:08:05 -0600

Quantispeed gravatar image

Hello

I would like to know how to make the preview of org.opencv.android.JavaCameraView fullscreen while on resolutions lower than the native screen resolution. (I´m trying to get 640x480). Right now the preview is a small square in the center of the screen. The device supports 640x480 both as Camera resolution and Preview resolution.

Before posting the question here, I did some research and wasn´t able to find any solutions. Let me explain what I have tried so far:

First, this is what I have:

  • Instead using CameraBridgeViewBase, I'm using a custom class, which extends JavaCameraView in order to be able to change the camera resolution.
public class JavaCamResView extends JavaCameraView {

public JavaCamResView(Context context, AttributeSet attrs) {
    super(context, attrs);
} 

public List<Camera.Size> getResolutionList() {      
    return  mCamera.getParameters().getSupportedPreviewSizes();  
    //return  mCamera.getParameters().getSupportedPictureSizes();
}

public void setResolution(Camera.Size resolution) {
    disconnectCamera();
    connectCamera((int)resolution.width, (int)resolution.height);      

}

public void setFocusMode (Context item, int type){
 ...
}   

public void setFlashMode (Context item, int type){
  ...
}   

public Camera.Size getResolution() {

    Camera.Parameters params = mCamera.getParameters(); 

    Camera.Size s = params.getPreviewSize();
    return s;
}
}

Layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<my.package.JavaCamResView
    android:id="@+id/surface_view"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

</relativelayout>

Finally the resolution is set inside the Activity onCameraViewStarted method:

public void onCameraViewStarted(int width, int height) {
    mRgba = new Mat(height, width, CvType.CV_8UC3);


    mResolutionList = mOpenCvCameraView.getResolutionList();

    for(Camera.Size resolution:mResolutionList){
        if(resolution.width == 640){
        mOpenCvCameraView.setResolution(resolution);
        }
    }

}

What I have tried so far:

  • added on onCreate: getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

  • added to Manifest: <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" />

  • mOpenCvCameraView.setMaxFrameSize(maxWidth, maxHeight)

  • Enclosing JavaCameraView layout inside a FrameLayout alone (instead of RelativeLayout) is not an option, since I need to show things on top of the preview.

Still no luck...

I´ve tried the code on different devices with same result (Current device is a Samsung SIII NEO, Android 4.4.2)

Thanks in advance!

Best regards

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2018-01-07 16:43:14 -0600

rabbit gravatar image

Did you solve this problem?

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-02-26 02:08:05 -0600

Seen: 3,249 times

Last updated: Feb 26 '15