Android自定义录像(一)之录像功能

本文介绍了Android项目中实现自定义录像的思路和关键代码,包括MediaRecorder、SurfaceView和Camera类的使用,以及自动对焦功能的实现。提供布局、权限配置和注意事项,为Android开发者提供参考。
摘要由CSDN通过智能技术生成

统一回复:该博客中所给出的demo代码已经不再维护。大致实现逻辑可以参考,Android版本等兼容性问题请自行寻找方案解决。


引言

最近在做一个项目,是有关用手机摄像头做图像实时识别的。所以里面需要自定义一个录像功能。该demo实现了录像录像后文件的保存查看,录像会实时自动对焦(AutoFocus)。根据功能分两篇讲述。这第一篇讲述录像基本实现思路和需要注意的点。


思路

*Android实现录像主要依靠MediaRecorder和SurfaceView这两个类。另外,因为需要对摄像头参数做一些设定,所以也需要Camera类。它们的作用分别是:MediaRecorder通过控制录像音视频源和输出编码等;surfaceview则是作为View的存在提供用户界面,在surfaceview的不同生命周期实现不同的操作;camera类则用于对摄像头参数做一些设定,再调用MediaRecorder的setCamera() 方法将camera对象带入。
##代码
####1.布局

<?xml version="1.0" encoding="utf-8"?>
	<FrameLayout android:layout_width="fill_parent"
	    android:layout_height="fill_parent"
	    android:baselineAligned="false"
	    xmlns:android="http://schemas.android.com/apk/res/android">
	    <SurfaceView
	        android:id="@+id/capture_surfaceview"
	        android:layout_width="fill_parent"
	        android:layout_height="fill_parent" />
	    <LinearLayout
	        android:orientation="horizontal"
	        android:layout_width="fill_parent"
	        android:layout_height="fill_parent"
	        android:baselineAligned="false">
	        <RelativeLayout
	            android:layout_gravity="left"
	            android:layout_width="0.0dip"
	            android:layout_height="fill_parent"
	            android:layout_weight="5.0">
	            <TextView
	                android:textSize="15.0sp"
	                android:textColor="@color/red_overlay"
	                android:id="@+id/capture_textview_information"
	                android:layout_width="wrap_content"
	                android:layout_height="wrap_content"
	                android:layout_margin="10.0dip"
	                android:layout_alignParentRight="true"
	                android:layout_alignParentBottom="true" />
	        </RelativeLayout>
	        <RelativeLayout
	            android:layout_gravity="right"
	            android:background="@color/white_overlay"
	            android:padding="20.0dip"
	            android:layout_width="0.0dip"
	            android:layout_height="fill_parent"
	            android:layout_weight="1.0"
	            android:alpha="0.3">
	
	            <ImageButton
	                android:id="@+id/capture_imagebutton_setting"
	                android:tag="setting"
	                android:background="@drawable/settings"
	                android:layout_width="wrap_content"
	                android:layout_height="wrap_content"
	                android:layout_alignParentTop="true"
	                android:layout_centerHorizontal="true"
	                android:contentDescription="@string/imagedescription" />
	            <ImageButton
	                android:id="
  • 10
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 15
    评论
评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值