0

I am coding an app for android which uses SurfaceView class to realize camera preview, which works well on Nexus Galaxy and Desire HD

The surface view layout width/height attribute is match_parent

But I encountered a problem: On SONY Xperia Z , the screen resolution is 1080p , but the largest preview resolution is 1280*720

Thus, my camera preview occupies only a part of full screen and other space are blank.

How can I make my preview full screen ?

petitchamp
  • 55
  • 7

1 Answers1

1

Resize your SurfaceView like this in landscape mode:

        // float camera_ratio = preview_size.width * preview_size / height; 
        ViewGroup.LayoutParams params = surfaceView.getLayoutParams();
        params.height = surfaceView.getHolder().getSurfaceFrame().height();
        params.width = Math.round(camera_ratio * params.height);
        surfaceView.setLayoutParams(params);

Or switch around some parameters if your app is in portrait mode.

edit: Holy moly, sorry for resurrecting this half year old question!