Mirco Widmer
Mirco Widmer

Reputation: 2149

Is getPreferredPreviewSizeForVideo() a good way go get the right preview size?

I'm building a part of an android app, that displays a camera preview. I'd like to set the correct (best) preview size possible for the current device.

To accomplish this, I used the following code:

public void surfaceChanged(SurfaceHolder surfaceHolder, int format, int w, int h) {
    Parameters parameters = camera.getParameters();
    List<Size> sizes = parameters.getSupportedPreviewSizes();

    // the list seems to be in that order, that the best quality is the first element
    parameters.setPreviewSize(sizes.get(0).width, sizes.get(0).height);

    camera.setParameters(parameters);
    camera.startPreview();
}

Now my question is, if the following method would be better to get the best preview quality for any device?

public void surfaceChanged(SurfaceHolder surfaceHolder, int format, int w, int h) {
    Parameters parameters = camera.getParameters();

    Size preferredSize = parameters.getPreferredPreviewSizeForVideo();
    parameters.setPreviewSize(preferredSize.width, preferredSize.height);

    camera.setParameters(parameters);
    camera.startPreview();
}

Currently I have just one device (Nexus 4) and on this one both methods result in the same. But I'm wondering, which method you would suggest.

Upvotes: 0

Views: 1330

Answers (2)

mAx
mAx

Reputation: 566

I can not really recommend using this method. On the Galaxy S4 this method returns a preferred video preview size of 176x144. Seems like the developers accidentally returned the smallest instead of the largest size here... if you use this as preview it looks ugly and even destroys the recorded video.

Upvotes: 3

Geobits
Geobits

Reputation: 22342

From the docs for getPreferredPreviewSizeForVideo():

Camcorder applications should set the preview size to a value that is not larger than the preferred preview size. In other words, the product of the width and height of the preview size should not be larger than that of the preferred preview size.

So, since it basically says the preview should not be bigger than the preferred size, this method should return the largest preview size available.

I'd also recommend using that method, because the list returned by getSupportedPreviewSizes() is not guaranteed to be in order. I haven't seen one out of order yet, but that doesn't mean that every device will honor it.

Upvotes: 0

Related Questions