1

I am working on developing an Android applications that uses camera. To display the camera preview, I observed a lot of examples using surface view or texture view. Why are these preferred over using ImageView to display the camera preview? I have used Imageview to display the preview and it works fine.

Thanks.

VK_nandi
  • 165
  • 1
  • 9
  • 1
    "I have used Imageview to display the preview and it works fine" -- what are you passing as the parameter to `setPreviewDisplay()` or `setPreviewTexture()` that works with an `ImageView`? – CommonsWare May 29 '15 at 18:30
  • I create a bitmap from the camera preview frame and set it to Imageview using **setImageBitmap()** method. For every frame from the camera, I update the Imageview with this method using a background handler. – VK_nandi May 29 '15 at 20:10
  • @user3027732 Oh my god! – Neon Warge Jul 05 '16 at 08:43
  • hey @user3027732 Bro...i also want more camera preview into single activity.[For Camera Filter e.g. iPhone Type Camera].. i need an see more camera preview into more image view and that all image view display into grid / list view..Please bro. help me. – Sagar Aghara Jan 09 '17 at 11:51
  • i also create a bitmap from the camera preview and set it to Imageview using setImageBitmap() method....but i want a Live Camera Preview into all ImageView.. i already asked this Questiion in below link.please check it.and help me if you know..(: http://stackoverflow.com/questions/41392791/how-to-apply-custom-filters-in-a-camera-surfaceview-preview – Sagar Aghara Jan 09 '17 at 11:52
  • you tell me.....how to Update the imageView using Background Handler. Please its an Urgent...(: – Sagar Aghara Jan 09 '17 at 11:57

2 Answers2

4

Please do not use ImageView for this. It is extremely inefficient, and I'd be surprised if you are able to produce high-resolution preview (1080p) with this approach.

SurfaceView and TextureView both directly push zero-copy buffers from the camera drivers to the hardware composer or the GPU, respectively. There are no extra buffer copies or transformations, except whatever final conversions need to be done at the destination. This reduces memory bandwidth and CPU overhead substantially.

Creating Bitmaps is slow, CPU-hungry, and makes several copies of each frame, wasting memory as well.

Eddy Talvala
  • 17,243
  • 2
  • 42
  • 47
1

Why are these preferred over using ImageView to display the camera preview?

Efficiency, among perhaps other reasons.

With both SurfaceView and TextureView, the underlying camera engine can work more directly with the output surface via the GPU and the OpenGL engine, bypassing the Dalvik/ART runtime. In your case, you are forcing the camera engine to fill in a Java byte[], then you are decoding it into a Bitmap, then updating the UI via your ImageView. That's a lot of extra CPU processing and memory fussing than is needed if you use a surface.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491