Ask Your Question

How to get camera preview sizes natively for Android & desktop

asked 2014-09-23 02:55:35 -0500

Ayberk Özgür gravatar image

I would like to know how to get the supported camera preview sizes on Android and desktop, possibly uniformly. I'm on a completely native framework (Qt) and would like to do this fully natively if possible. Currently, I'm using VideoCapture to get image data on both platforms but the size is basically guessed.

edit retag flag offensive close merge delete


Does this look like what you're are looking for? QCameraImageCapture::supportedResolutions

rwong gravatar imagerwong ( 2014-09-28 05:19:03 -0500 )edit

Also, two things. Firstly, strictly speaking this question is a question about Qt, and only marginally related to OpenCV - or not at all. Therefore it is somewhat out-of-topic here. Secondly, please do not downvote an answer just because it did not solve your problem. This is especially important if the answer does not contain any bad-will, as it sends an unfriendly message to users of OpenCV forum. If it did not solve your problem, you can simply leave it unvoted and explain your reason, so that it will remain at zero vote. A negative vote should only be used when the answer is unfriendly, or contain misleading or clearly wrong information. In itay's case, it is what I would have suggested as well - to obtain the parameters on the Java side, during application startup.

rwong gravatar imagerwong ( 2014-09-28 05:24:24 -0500 )edit

First, this question is perfectly related to OpenCV: In order to even be able to get the live camera image in a hardware independent manner, you first need the supported preview sizes. As OpenCV provides the mechanism to access the camera (VideoCapture), it should provide the mechanism to access the supported preview sizes as well. I shouldn't need Qt or any other platform to obtain this information. See my answer below.

Ayberk Özgür gravatar imageAyberk Özgür ( 2014-09-29 09:27:48 -0500 )edit

Second, I don't believe that downvotes are reserved for "bad behavior" or "clearly wrong information", it also applies to where an answer is obviously found from the first page on Google search results. Honestly, try searching for "android get camera preview sizes"; no one should ask some question here whose answer can be found easily on Google (or whose answer is RTFM). Moreover in this case, the code desired in the question has a nativity priority. The given answer "You can try using android.hardware.Camera parameters like this:" obviously indicates that the answerer did not even properly read the question, let alone considering giving an answer in the case that he/she is not familiar with the meaning of "native".

Ayberk Özgür gravatar imageAyberk Özgür ( 2014-09-29 09:31:47 -0500 )edit

I think these kinds of answers just clutter the Q&A space and give the impression that this is not a competent community, hence the downvote.

Also, there is a "flag offensive" button in the answers for "unfriendly" behavior.

Ayberk Özgür gravatar imageAyberk Özgür ( 2014-09-29 09:32:40 -0500 )edit

2 answers

Sort by » oldest newest most voted

answered 2014-09-29 09:09:49 -0500

Ayberk Özgür gravatar image

In Android, the following can be done to get the list of supported preview resolutions:

cv::VideoCapture camera(0);;
union {const char* str; double res;} previewSizes;
previewSizes.res = camera.get(CV_CAP_PROP_SUPPORTED_PREVIEW_SIZES_STRING);

This will yield a string as follows:


The string needs parsing - not that difficult. This information is extracted by following the source code and it is not documented; any platform-specific camera capture code is in fact not documented. I will try to add the proper documentation to at least the Android side with a PR in the future.

edit flag offensive delete link more

answered 2014-09-28 03:44:41 -0500

itay gravatar image

updated 2014-09-28 05:31:47 -0500

You can try using android.hardware.Camera parameters like this:

camera =;
parameters = camera.getParameters();
List<Size> SupporetdSizes =  parameters.getSupportedPreviewSizes()
edit flag offensive delete link more


Natively if possible please, this is the generic Java way that I'm already aware of. And this isn't even preview sizes, it's picture sizes.

Ayberk Özgür gravatar imageAyberk Özgür ( 2014-09-28 04:09:23 -0500 )edit

You right I mean parameters.getSupportedPreviewSizes()

itay gravatar imageitay ( 2014-09-28 04:44:27 -0500 )edit

@itay: please edit this into your answer. Thanks.

rwong gravatar imagerwong ( 2014-09-28 05:26:01 -0500 )edit
Login/Signup to Answer

Question Tools


Asked: 2014-09-23 02:55:35 -0500

Seen: 2,385 times

Last updated: Sep 29 '14