android 拍照 Camera类 使用照相机进行拍照 翻译

  次阅读 来源:互联网(转载协议) 2015-09-29 10:11 我要评论(0)


The Camera class is used to set image capture settings, start/stop preview, snap pictures, and retrieve frames for encoding for video. This class is a client for the Camera service, which manages the actual camera hardware.




To take pictures with this class, use the following steps:

获取个Camera实例 open(int).获取已经存在(默认)的设置 getParameters().如果必要,可以修改返回的 Camera.Parameters 对象 and 调用setParameters(Camera.Parameters).如果需要,也可以调用 setDisplayOrientation(int).重要: 传递一个完全初始化后的 SurfaceHolder 到setPreviewDisplay(SurfaceHolder). Without a surface, the camera will be unable to start the preview.重要: 调用startPreview() 更新预览界面,预览必须在你拍照之前启动。 当你想要的时候,调用takePicture(Camera.ShutterCallback, Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback) 来捕获一张照片.等待 回调函数提供实际的图像数据。 照完之后,预览显示将会停止。如果想照更多的照片,请再次调用 startPreview() .调用 stopPreview() 来通知更新预览界面。重要: 调用release() 来释放相机,让其他应用程序使用. 应用程序应该用onPause() (and re-open() it inonResume())来立即释放相机.

To quickly switch to video recording mode, use these steps:

Obtain and initialize a Camera and start preview as described above. Call unlock() to allow the media process to access the camera.Pass the camera to setCamera(Camera). SeeMediaRecorder information about video recording.When finished recording, call reconnect() to re-acquire and re-lock the camera.If desired, restart preview and take more photos or videos. Call stopPreview() andrelease() as described above.

This class is not thread-safe, and is meant for use from one event thread. Most long-running operations (preview, focus, photo capture, etc) happen asynchronously and invoke callbacks as necessary. Callbacks will be invoked on the event thread open(int) was called from. This class's methods must never be called from multiple threads at once.

这个类不是线程安全的,并且是供一个事件线程使用。最长时间运行的操作(预览,对焦,照片拍摄等)发生 异步调用的回调是必要的。回调将在事件线程open(int)被调用后被调用。这个类的方法,绝不能从多个线程立即调用。

Caution: Different Android-powered devices may have different hardware specifications, such as megapixel ratings and auto-focus capabilities. In order for your application to be compatible with more devices, you should not make assumptions about the device camera specifications.


Public Methods公共

final void

addCallbackBuffer(byte[] callbackBuffer) Adds a pre-allocated buffer to the preview callback buffer queue.

final void

autoFocus(Camera.AutoFocusCallback cb) Starts camera auto-focus and registers a callback function to run when the camera is focused.

final void

cancelAutoFocus() Cancels any auto-focus function in progress.

final boolean

enableShutterSound(boolean enabled)

Enable or disable the default shutter sound when taking a picture.拍摄时启用或禁用默认的快门声。

static void

getCameraInfo(int cameraId, Camera.CameraInfo cameraInfo) Returns the information about a particular camera.

static int

getNumberOfCameras() Returns the number of physical cameras available on this device.返回物理相机在此设备上可用的数目


getParameters() Returns the current settings for this Camera service.


  • teamLab创始人猪子寿之: 抛去衣食住行,我还剩下什么?

    teamLab创始人猪子寿之: 抛去衣食住行,我还剩下什么?

  • 2018深圳国际人工智能展览会 2018 shenzhen International Artif

    2018深圳国际人工智能展览会 2018 shenzhen International Artif

  • Oculus公布原型机,大幅度提升可视角,能实现140°的视场水平


  • Michael I. Jordan带你解读百万奖金ATEC蚂蚁人工智能大赛

    Michael I. Jordan带你解读百万奖金ATEC蚂蚁人工智能大赛



近日,美国软性机器抓手制造商 Soft Robotics 宣布,获得 2000 万美元的融资,本轮投资者包括 Scale Venture Partners,Calibrate Ventures...

据外媒报道,加州车管局发布了《2017自动驾驶脱离报告(California Autonomous Vehicle Disengagement Reports)》,其中谈及了脱离的具体...