Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does android handle differences between preview size/ratio and actual SufaceView size?

I'm writing a small android app where a user can place an image inside the live preview of the camera and take a picture of this. The app will then combine the two images appropriately -- All of this is working fine.

I understand you can get/set the PreviewSize using Camera.getParameters(), I assume this is related to the size of the realtime "camera feed".

However, the size of my SurfaceView where the camera preview is shown is different from the reported (and used) PreviewSizes. For example, in the emulator my available SurfaceView happens to be 360x215, while the PreviewSize is 320x240. Still, the entire SurfaceView is filled with the preview.

But the picture that's generated in the end is (also?) 320x240. How does android compensate for these differences in size and aspect ratio? Is the image truncated?

Or am I simply misunderstanding what the PreviewSize is about - is this related to the size of the generated pictures, or is it related to the "realtime preview" that's projected on the SurfaceView? Are there any non-trivial Camera examples that deal with this?

I need to know how what transformation takes place to, eventually, copy/scale the image correctly into the photo, hence these questions.

like image 317
Ivo van der Wijk Avatar asked Jan 09 '12 21:01

Ivo van der Wijk


1 Answers

I am trying to figure this out myself. Here is what I found out so far..

  • The surface view has an internal surface called mSurface which is actually used as camera feed and the encoder feed. So this buffer has to be the actual size at which you want do the recording.
  • You can set the size of this mSurface to be independent of the SurfaceView by using the setFixedSize method
  • Now you might want to perform a HD recording so the mSurface needs to 1280x760 resolution but you SurfaceView can't be that big (Assuming you are running it on a phone with a WVGA screen). So you try to set to a smaller resolution than 1280x760 which also maintains the same aspect ratio.
  • Android now performs a resizing on the HD buffer to get the preview resolution, cropping is not done, it is just resized to the SurfaceView reoslutions
  • So at this point both the mSurface and the previewSize that you set to the camera is the same resolution and hence the resultant video recording will also be of the same resolution.

That being said I am still struggling to get my VGA recorder to work on Nexus S, it is working on a LG Maha device. :)

like image 171
bluefalcon Avatar answered Oct 23 '22 02:10

bluefalcon