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.


  • 英国研发“杀生”机器人 通过生命体获取能量

    英国研发“杀生”机器人 通过生命体获取能量

  • 韩春雨称已能重复实验结果 近期将有消息公布

    韩春雨称已能重复实验结果 近期将有消息公布

  • 无人驾驶汽车如何改变城市生活?听听他们怎么说


  • 未来两年人工智能要怎么走?看这篇就够了




霍金 视觉中国 图 英国著名物理学家霍金(Stephen Hawking)再次就人工智能(AI)发声,他认为:对于人类来说,强大AI的出现可能是最美妙的...

文|郑娟娟 今年,人工智能(AI) 60岁了。在AI60岁的时候,笔者想要介绍一下AI100,一个刚刚2岁的研究项目,但它的预设寿命是100年,甚至更长...

AlphaGo与李世石的人机大战,为大众迅速普及了人工智能的概念。 但对谷歌而言,除了下围棋,现在的人工智能进展到哪一步了?未来,人工智能...