Android Camera API 1.0,2.0,3.0 知多少

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android Camera API 1.0,2.0,3.0 知多少相关的知识,希望对你有一定的参考价值。

参考技术A   看到源码里面有诸如Camera.h , Camera2.h, Camera3.h的文件,觉得奇怪,后面在Camera3.h

  中找到了对前后3个版本的概要性描述。

  BTW, 我们看代码的过程中,如何避免不需要的文件被添加到工程?

  我是指: 我只想看Camera3.0的代码,怎么去除掉其他版本的呢?

  不知道各位是否知道这些牵涉到哪些文件? 谢谢!!

  * S1. Version history:
  * 1.0: Initial android camera HAL (Android 4.0) [camera.h]:
  *
  * - Converted from C3;3; CameraHardwareInterface abstraction layer.
  *
  * - Supports android.hardware.Camera API.
  *
  * 2.0: Initial release of expanded-capability HAL (Android 4.2) [camera2.h]:
  *
  * - Sufficient for implementing existing android.hardware.Camera API.
  *
  * - Allows for ZSL queue in camera service layer
  *
  * - Not tested for any new features such manual capture control, Bayer RAW
  * capture, reprocessing of RAW data.
  * 3.0: First revision of expanded-capability HAL:
  *
  * - Major version change since the ABI is completely different. No change to
  * the required hardware capabilities or operational model from 2.0.
  *
  * - Reworked input request and stream queue interfaces: Framework calls into
  * HAL with next request and stream buffers already dequeued. Sync framework
  * support is included, necessary for efficient implementations.
  *
  * - Moved triggers into requests, most notifications into results.
  *
  * - Consolidated all callbacks into framework into one structure, and all
  * setup methods into a single initialize() call.
  * - Made stream configuration into a single call to simplify stream
  * management. Bidirectional streams replace STREAM_FROM_STREAM construct.本回答被提问者和网友采纳

Android 音视频开发:使用 Camera API 采集视频数据

本文主要将的是:使用 Camera API 采集视频数据并保存到文件,分别使用 SurfaceView、TextureView 来预览 Camera 数据,取到 NV21 的数据回调。

注: 需要权限:<uses-permission android:name="android.permission.CAMERA" />

一、预览 Camera 数据

做过Android开发的人一般都知道,有两种方法能够做到这一点:SurfaceView、TextureView。

下面是使用SurfaceView预览数据的方式:

SurfaceView surfaceView;
Camera camera;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

surfaceView = (SurfaceView) findViewById(R.id.surface_view);
surfaceView.getHolder().addCallback(this);

// 打开摄像头并将展示方向旋转90度
camera = Camera.open();
camera.setDisplayOrientation(90);

}

//------ Surface 预览 -------
@Override
public void surfaceCreated(SurfaceHolder surfaceHolder) {
try {
camera.setPreviewDisplay(surfaceHolder);
camera.startPreview();
} catch (IOException e) {
e.printStackTrace();
}
}


@Override
public void surfaceChanged(SurfaceHolder surfaceHolder, int format, int w, int h) {

}

@Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
camera.release();
}

下面是使用TextureView预览数据的方式:

    TextureView textureView;
    Camera camera;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        textureView = (TextureView) findViewById(R.id.texture_view);
        textureView.setSurfaceTextureListener(this);// 打开摄像头并将展示方向旋转90度
        camera = Camera.open();
        camera.setDisplayOrientation(90);
    }
//------ Texture 预览 ------- @Override public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i1) { try { camera.setPreviewTexture(surfaceTexture); camera.startPreview(); } catch (IOException e) { e.printStackTrace(); } } @Override public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int i, int i1) { } @Override public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) { camera.release(); return false; } @Override public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) { }

 







































以上是关于Android Camera API 1.0,2.0,3.0 知多少的主要内容,如果未能解决你的问题,请参考以下文章

Android之camera1和2的简单使用

Android之camera1和2的简单使用

如何使用 Camera 2 API Android 提高捕获图像的质量?

Android Camera 2 API 在 Nougat 7.1 上的 flash 问题

问题支持Android相机的API和camera2 API问题,怎么解决

在 Android 中基于叠加层裁剪位图 - Camera API 2