android R 两个camera同时预览、画中画

关于布局

画中画效果

画中画效果代码实现

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

        <com.android.DualCamera.camera2.AutoFitTextureView
            android:id="@+id/texture_preview"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">
        <com.android.DualCamera.camera2.AutoFitTextureView
            android:id="@+id/texture_preview2"
            android:layout_width="320dp"
            android:layout_height="240dp" />
    </LinearLayout>
</RelativeLayout>

并列效果

并列效果代码实现

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

        <com.android.DualCamera.camera2.AutoFitTextureView
            android:id="@+id/texture_preview"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1" />

        <com.android.DualCamera.camera2.AutoFitTextureView
            android:id="@+id/texture_preview2"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="fill_parent"/>
    </LinearLayout>
</RelativeLayout>

布局中使用 AutoFitTextureView 代替 TextureView。AutoFitTextureView 继承自 TextureView,能够根据传入的宽高值调整自身大小,目的是使预览画面不变形。AutoFitTextureView的代码实现在google android-Camera2Basic-master项目中,github上就可以下载。

参考的app 的demo:

camera2例子:
https://github.com/wangshengyang1996/Camera2Demo

使用camera2 api打开逻辑多摄来同时打开多个物理摄像头:
https://download.csdn.net/download/qq_32503365/12542520

Camera2 如何同时开启前后摄像头Preview并进行录像?
https://ask.csdn.net/questions/750899

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值