赞
踩
通常情况下,调用android系统相机基本上可以满足拍照的需求,而自定义相机的需求一般来自于开发自己的相机应用,今天我们来简单聊聊android自定义相机的实现,限于篇幅,我们上篇只讨论android.hardware.Camera,下篇我会和大家一起讨论一下android.hardware.Camera2
首先简单看一下用到的类有哪些:
类名 | 介绍 | 注释 |
---|---|---|
Camera | android 5.0 之前控制相机硬件是通过这个Camera类实现的 | deprecated in API level 21. |
Camera.Parameters | 控制相机的参数,如对焦,闪光灯等 | deprecated in API level 21. |
SurfaceView | 专注于绘制应用层内嵌浮层的类,这里我们用它来预览镜头的取景 | \ |
SurfaceHolder | 持有一个展示的surface的抽象接口。允许你控制surface的尺寸和格式,编辑surface中的像素和监听surface的改变。 | \ |
SurfaceHolder.Callback | 控制该接口的客户端能够接收surface改变的信息。 | \ |
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
在camera的官方接口文档中,给出了控制camera的10个步骤,很详细,我们这边侧重于实现。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/camera_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Camera.CameraActivity">
<FrameLayout
android:id="@+id/camera_preview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"/>
<LinearLayout
android:id="@+id/control"
android:layout_width="match_parent"
android:layout_height=

赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。