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

I am writing a small Android application where a user can put an image in a camera preview and take a picture. Then the application will combine the two images, respectively - all this works fine.

I understand that you can get / set PreviewSize using Camera.getParameters (), I assume that this is due to the size of the "camera" in real time.

However, the size of my SurfaceView, where the camera preview is displayed, is different from the PreviewSizes (and used). For example, in an emulator, my available SurfaceView is 360x215, and PreviewSize is 320x240. However, the entire SurfaceView is populated with a preview.

But the image that is generated at the end is (also?) 320x240. How does an android compensate for these differences in size and aspect ratio? Is the image trimmed?

Or I just don’t understand what PreviewSize is - is it due to the size of the generated images or is it related to the “real-time preview” that is projected onto the SurfaceView? Are there any non-trivial camera examples that relate to this?

I need to know how the conversion occurs in order to ultimately copy / scale the image to the photo, therefore, these issues.

+8
android image camera preview surfaceview
source share
1 answer

I'm trying to figure it out myself. Here is what I have found out so far.

  • The surface has an inner surface called mSurface , which is actually used as camera feed and encoder feed. So this buffer should be the actual size on which you want to record.
  • You can set the size of this mSurface independent of SurfaceView using the setFixedSize method
  • Now you can record HD so that mSurface requires a resolution of 1280x760, but you SurfaceView cannot be so large (suppose you use it on a phone with a WVGA screen). Therefore, you are trying to set a lower resolution than 1280x760, which also supports the same aspect ratio.
  • Android now resizes in the HD buffer to get preview permission, cropping does not work, it just changes to SurfaceView reoslutions
  • So, at this moment, both the mSurface and previewSize parameters that you set for the camera have the same resolution and, therefore, the resulting video will have the same resolution.

Saying I'm still trying to get my VGA recorder to work on the Nexus S, it works on the LG Maha device. :)

+1
source share

All Articles