Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
368 views
in Technique[技术] by (71.8m points)

android - use camera without surfaceview or textureview

I have been trying to figure out if there is a way to use camera to take either video/pictures without defining surfaceview or textureview. I found this link: Use Android Camera without surface View

I used this trick with textureview on my nexus tablet but no luck! Also, http://handycodeworks.com/?p=19 says that this approach doesn't work on all the devices.

Does anyone have any idea if there is a way to do it at all? or its just something which android framework doesn't support at all and the GUI has to have some surface/texture element in layout? Then the only option is to just manipulate the layout so its not visible on the screen as per the app requirements.

EDIT 1: As explained in the above link http://handycodeworks.com/?p=19, I tried the below code:

public class CameraCapture {

  // I pass the getApplicationContext() from the main activity.
  public void startCameraCapture(Context contx) {
    SurfaceView sv = new SurfaceView(contx);
    mCamera = Camera.open();
    mCamera.setPreviewDisplay(sv.getHolder());
    mCamera.setPreviewCallback(new PreviewCallback() {
      @Override
      public void onPreviewFrame(byte[] data, Camera camera) {
        Log.v("TAG", "on preview frame called");
      }
    Thread.sleep(1000);
    mCamera.startPreview();
}

However, onPreviewFrame() never invoked. Am I missing something?

EDIT 2:

Is it possible to do in native code? Capturing video/using camera without GUI element (surfaceview/textureview) using OpenCV? I looked at this link: http://docs.opencv.org/trunk/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.html#application-development-with-static-initialization. However, they also show the sample code with some camera view element defined in main layout xml file.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I'm able to do it by defining SurfaceTexture object as below:

SurfaceTexture surfaceTexture = new SurfaceTexture(10);
<camera object>.setPreviewTexture(surfaceTexture);

In this, I don't need to define a GUI element in the app.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...