API使预览填充整个视图

API使预览填充整个视图

本文介绍了Camera2 API使预览填充整个视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google Samples中的Camera2Basic示例( https://github.com/googlesamples/android -Camera2Basic )在片段中显示相机预览.该片段包含一个RelativeLayout和一个自定义的AutoFitTextureView.后者可以在上面的链接中找到.我已调整布局以使预览居中并删除控制按钮:

I am using the Camera2Basic example from Google Samples (https://github.com/googlesamples/android-Camera2Basic) to display a camera preview inside a fragment.This fragment contains a RelativeLayout and a custom AutoFitTextureView. The latter can be found on the link above. I have adjusted the layout to center the preview and remove control buttons:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/camera_rel">

    <uk.co.deluxe_digital.messngr.AutoFitTextureView
    android:id="@+id/texture"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true" />

</RelativeLayout>

我在ViewPager中显示了三个片段.我确实对Camera2BasicFragment进行了一些小的更改,使其成为与我的ViewPager一起使用并删除按钮的android.support.v4.app.Fragment.

I have three total fragments that are displayed within a ViewPager. I did make some small changes to the Camera2BasicFragment to make it an android.support.v4.app.Fragment to work with my ViewPager and remove the buttons.

我想让相机预览充满整个屏幕.这可以通过拉伸预览图像来实现.那不是我想要的.有谁知道放大预览或TextureView的方法,以使预览的高度与容器匹配,即使裁切了侧面也是如此.我希望它填充视图并保持宽高比.这将意味着双方的某些预览都将丢失,但这没关系.

What I would like is to make the camera preview fill the entire screen. This is possible by stretching the preview image. That is not what I want. Does anyone know a way of scaling up the preview or TextureView so that the height of the preview matches the container even if the sides are cropped off. I would like it to fill the view and maintain aspect ratio. This would mean that some of the preview at either side is lost, but that is okay.

这是我目前拥有的:

This is what I currently have:

FloatingActionButton负责捕获图像.那是主要的父母活动.

The FloatingActionButton takes care of capturing the image. That is on the main parent activity.

即使您能为我指出正确的解决方案,那也将是巨大的帮助!

Even if you can point me in the right direction to working this out, that would be a huge help!

推荐答案

AutoFitTextureView扩展了TextureView以保持宽高比.如果您想填满整个屏幕,请使用:

AutoFitTextureView extends TextureView to keep aspect ratio.If you want to fill the entire scree, just use:

<TextureView
    android:id="@+id/texture"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
 />

这篇关于Camera2 API使预览填充整个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 17:40