Android的画像锁定相机preVIEW [英] Android portrait locked Camera Preview

查看:193
本文介绍了Android的画像锁定相机preVIEW的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了相机preVIEW只是因为它是Android中的应用ApiDemos。
事情是,我想我的活动,其中显示在preVIEW被锁定为纵向。所以我在清单中设置screenOrientation为纵向。

I have implemented the Camera Preview just as it is in the ApiDemos application of Android. The thing is that I want my activity, where the Preview is shown to be locked to portrait. So I set screenOrientation to portrait in the manifest.

在'getOptimal previewSize的方法为preVIEW,意义,当它需要返回480x720,该方法返回720×480返回相反的价值观,我在我的的FrameLayout小preVIEW中心活动(这是不是我想要的,我想它匹配的父(是的,布局与match_parent中定义)。

The 'getOptimalPreviewSize' method returns opposite values for the preview, meaning, when it's needed to return 480x720, the method returns 720x480, and I have small preview centered in my FrameLayout of the activity (which is not what I want, I want it to match the parent (yes, the layout is defined with "match_parent").

我试过:


  • setDisplayOrientation(90);

  • parameters.set(方向,肖像);

  • parameters.set(旋转,90);

似乎没有任何帮助。

为什么我不能纵向显示模式下,相机的preVIEW?锁定。

Why can't I show Preview of the Camera in portrait mode? Locked.

感谢

推荐答案

下面是SurfaceView相机的人像preVIEW工作的例子:

Here is a working example of a portrait preview of camera on SurfaceView :

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.surface);
    surfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {

        private Camera camera;

        @Override
        public void surfaceCreated(SurfaceHolder holder) {
            try {
                camera = Camera.open();
                camera.setPreviewDisplay(holder);
                camera.setDisplayOrientation(90);
                camera.startPreview();
            } catch (IOException e) {
                Log.e(TAG, "Error", e);
            }
        }

        @Override
        public void surfaceDestroyed(SurfaceHolder holder) { 
            camera.stopPreview();
        }

        @Override
        public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
        }
    });
}

通过以​​下布局文件:

With the following layout file:

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

    <SurfaceView
        android:id="@+id/surface"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</FrameLayout>

这篇关于Android的画像锁定相机preVIEW的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆