1

I am using the Intel Inde library for media (specifically this example: https://github.com/INDExOS/media-for-mobile/blob/master/Android/samples/apps/src/com/intel/inde/mp/samples/CameraCapturerActivity.java)

My goal is to set up a full screen preview in portrait mode and record videos in portrait mode. Everything works great in landscape mode(full screen preview and recording). However in portrait mode I can't stretch the preview to fill the screen vertically (even though I set the surface view to max size). The largest size I get is a square image preview. I have tried making the surface view larger then the screen, but still stuck with a square preview and recording.

This is what my preview screen currently looks like: https://i.stack.imgur.com/0mNIb.jpg

Here is my code:

public void createCamera() 
{
    Camera camera = Camera.open();
    Camera.Parameters parameters = camera.getParameters();

    List<Camera.Size> supportedResolutions = camera.getParameters().getSupportedPreviewSizes();
    parameters.setPreviewSize(supportedResolutions.get(0).width,   
    supportedResolutions.get(0).height);
    camera.setDisplayOrientation(90);  
    camera.setParameters(parameters);
}

public void createPreview() 
{
     GLSurfaceView surfaceView = new GLSurfaceView(getActivity().getApplicationContext());

     //This code is used to get display size to set surface view size
     Display display = getActivity().getWindowManager().getDefaultDisplay();
     Point size = new Point();
     display.getSize(size);
     int width = size.x;
     int height = size.y;

     surfaceView.setLayoutParams(new FrameLayout.LayoutParams(width, height));

     //Used to test that the surfaceview does cover the whole screen
     //surfaceView.setBackgroundColor(Color.RED);

     ((RelativeLayout)view.findViewById(R.id.myview)).addView(surfaceView, 0);

     preview = capture.createPreview(surfaceView, camera);
     preview.start();           
 }
Marlon
  • 1,473
  • 11
  • 13
nyc0202034
  • 113
  • 1
  • 3
  • 14
  • Do you want it to distort to fill the screen vertically, or retain the correct aspect ratio? – fadden Feb 12 '15 at 18:28
  • I would like the correct aspect ratio and fill vertically (similar if I use the default camera app and get a full screen undistorted preview) – nyc0202034 Feb 12 '15 at 19:15

2 Answers2

1

There is a thread on the Intel Developer site, appears to be the same issue. They have a solution, but you have to request the library update via email:

https://software.intel.com/en-us/forums/topic/542633

Art Haedike
  • 1,772
  • 2
  • 16
  • 13
0

I think your problem is that you are setting the preview size of your camera to the first size in the list of supported sizes.

List<Camera.Size> supportedResolutions = camera.getParameters().getSupportedPreviewSizes();
parameters.setPreviewSize(supportedResolutions.get(0).width, supportedResolutions.get(0).height);

What you should do is loop through the list of supported sizes and find a size that closely matches the screen's size/resolution.

You can check this SO answer for sample code snippets

Update

The next step would be to debug it and find out why it didn't work for you. What I would do in your case would be to print out the contents of the supportedResolutions list. Since you already the have the display size, I would compare the display size to the different sizes in the supportedResolutions list and also to the size returned from the getOptimalSize method. It's possible that the getOptimalSize method didn't find an optimal size and the method may need to be tweaked to your need. I tweaked mine to get it to work.

Let me know if you need more help.

Community
  • 1
  • 1
iRuth
  • 2,737
  • 3
  • 27
  • 32
  • iRuth, I've implemented the getOptimalSize() method from the SO answer you mentioned, and the result is still the same. No difference :( – nyc0202034 Feb 12 '15 at 19:42
  • I'm debugging on an HTC one if that makes any difference. I added some debug lines, and can confirm that getOptimalSize does return a valid size(1920x1088). Are you getting a full screen preview in portrait mode? – nyc0202034 Feb 12 '15 at 20:47
  • Yes I did get a full screen preview in portrait mode. – iRuth Feb 12 '15 at 21:01
  • Are you using a GLSurfaceView, or something else? Do you mind sharing your code? Maybe I missed something. – nyc0202034 Feb 12 '15 at 21:12
  • @nyc0202034 No, I am using `SurfaceView` but I don't think that should matter. What is the size returned by `display` in your `createPreview` method? – iRuth Feb 12 '15 at 22:38
  • I get a display size of 1920x1080 (phone's resolution) – nyc0202034 Feb 12 '15 at 23:23
  • That's odd. Can you try swapping the width and the height for the `GLSurfaceView` and/or camera and see if that changes anything? – iRuth Feb 13 '15 at 00:01