Android相机的使用

在Android手机中,相机应该算是每部智能手机的标准配置了,google为了方便开发者开发,提供了一套供开发者使用的api,作为软件开发者基本上只要调用这些接口就可以进行Android相机方面的功能开发了(这里指的只是基本功能,比如预览、拍照等)!

在本篇博客中将想你展示如何使用google提供的接口(Camera1,后面还会说到,google在后期的版本中推出了Camera2接口,在下一篇博客中在介绍如何使用Camera2接口)开发自己的相机。在这里使用到的类不多,主要包含:Camera、SurfaceView、SurfaceHolder等!

google在相机预览、拍照包括人脸识别中都提供了一个接口,直接调用就可以实现相应的功能,是不是感觉很简单,下面我们就来实现一个Camera(具有预览拍照功能,拍照的图片储存在这里就不实现了)!
先看一下布局文件吧:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

        <android.support.v4.widget.DrawerLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
                <FrameLayout
                    android:background="@android:color/transparent"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <SurfaceView
                        android:background="@android:color/transparent"
                        android:id="@id/camera_preview"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent" />
                </FrameLayout>
            <LinearLayout
                android:layout_width="150dp"
                android:layout_height="300dp"
                android:layout_gravity="start|center_vertical"
                android:background="@color/colorPrimary" />
        </android.support.v4.widget.DrawerLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:background="@android:color/transparent">

            <ImageView
                android:onClick="onCapturePhoto"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:background="@android:color/transparent"
                android:src="@drawable/photo_button" />
        </RelativeLayout>


</RelativeLayout>

写的有点啰嗦,其实要做demo的话,只需要一个SurfaceView即可,其他的即可抛弃!!!

再来看一下java代码的实现:

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值