0

This is my first question. I need to help for live camera on android. I want to create camera preview(on surface view). android application for android with some function:

  • Flip mirror camera in live preview camera. (It's same rotateX or rotateY).

I was try flip bitmap on Camera.PreviewCallback then redraw Surface but it very slow. Then I try using open cv. But it to larger for my application.

[Android api >= 10.]

Give me some idea to fix my prob. Thanks so much. // Sorry for my english.

quangson91
  • 1,044
  • 1
  • 16
  • 30
  • [SurfaceTexture](http://developer.android.com/reference/android/graphics/SurfaceTexture.html), available for **API >= 11**, let's you performed this really smoothly and easily. – Alex Cohn Jan 27 '14 at 19:17
  • Thank you so much. But my app need android api >= 10. if I have no way I will use SurfaceTexture :). – quangson91 Jan 29 '14 at 00:28

1 Answers1

0

If you cannot use SurfaceTexture, consider hiding the preview surface (you still need a live SurfaceView to launch Camera.startPreview()). Use Camera.PreviewCallback(), push the YUV frames to an OpenGl texture via a shader, and render them in OpenGL. See Android OpenGL ES process yuv preview as RGBA as a starting example.

I strongly suggest to build separate code for API >= 11 with SurfaceTexture, because the system is getting much more strict in enforcing visible live preview with every upgrade. It is still possible to hide the SurfaceView, but for API <= 10 you could simply move it to (10000, 10000) and not use more sophisticated and less robust workarounds.

Community
  • 1
  • 1
Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • Thanks so much :) Can you give an example SurfaceTexture to display camera ? I've try but it's not working. I use TextureView to display camera, then I use setRotateY to flip image. What method I use on SurfaceTexture to flip camera ?. – quangson91 Feb 04 '14 at 08:35
  • You can see a minimal example [on GitHub](https://github.com/alexcohn/OpenGLCamera). – Alex Cohn Feb 04 '14 at 12:16
  • Thank you so much. But in your example you use TextureView => android api >= 14 (it's not 11). – quangson91 Feb 04 '14 at 16:07
  • Oops. See this: http://stackoverflow.com/questions/13200652/displaying-the-camera-stream-on-a-glsurfaceview-via-surfacetexture – Alex Cohn Feb 04 '14 at 16:34