android.hardware.camera源码,android.hardware.Camera

1. android.hardware.Camera

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 access the device camera, you must declare themanifest element to declare camera features used by your application. For example, if you use the camera and auto-focus feature, your Manifest should include the following:

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

Obtain an instance of Camera from

Get existing (default) settings with

If necessary, modify the returned

Important: Pass a fully initialized

Important: Call

After taking a picture, preview display will have stopped. To take more photos, call

Call

Important: Call

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

Obtain and initialize a Camera and start preview as described above.

Call

Pass the camera to

When finished recording, call

If desired, restart preview and take more photos or videos.

Call

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

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.

Developer Guides

For more information about using cameras, read theCameradeveloper guide.

2. Building a Camera App

Some developers may require a camera user interface that is customized to the look of their application or provides special features. Creating a customized camera activity requires more code thanusing an intent, but it can provide a more compelling experience for your users.

The general steps for creating a custom camera interface for your application are as follows:

Detect and Access Camera - Create code to check for the existence of cameras and request access.

Create a Preview Class - Create a camera preview class that extends

Build a Preview Layout - Once you have the camera preview class, create a view layout that incorporates the preview and the user interface controls you want.

Setup Listeners for Capture - Connect listeners for your interface controls to start image or video capture in response to user actions, such as pressing a button.

Capture and Save Files - Setup the code for capturing pictures or videos and saving the output.

Release the Camera - After using the camera, your application must properly release it for use by other applications.

Camera hardware is a shared resource that must be carefully managed so your application does not collide with other applications that may also want to use it. The following sections discusses how to detect camera hardware, how to request access to a camera, how to capture pictures or video and how to release the camera when your application is done using it.

Caution: Remember to release the

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值