Android相机 - 一半的屏幕是黑色人像模式 [英] Android Camera - Half of the screen is black in Portrait mode

查看:187
本文介绍了Android相机 - 一半的屏幕是黑色人像模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创造的相机应用,但我已经遇到这个问题:在横向模式下使用相机时一切正常,但使用与setDisplayOrientation纵向(90)方法带来了这个问题:

一半的屏幕是黑的。

形象在这里: http://i.stack.imgur.com/sPTex.jpg

surfaceCreated方式:

  @覆盖
    公共无效surfaceCreated(SurfaceHolder持有人){
        尝试{
            this.camera = Camera.open();
            this.camera.setDisplayOrientation(90);
            this.camera.set previewDisplay(this.holder);
        }赶上(IOException异常五){
            e.printStackTrace();
        }
    }

我的XML布局

 <?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:方向=垂直>
    <的FrameLayout
        机器人:ID =@ + ID /摄像机preVIEW
        机器人:layout_width =match_parent
        机器人:layout_height =0dip
        机器人:layout_weight =1>
    < /&的FrameLayout GT;
    <按钮
        机器人:ID =@ + ID / analyzeButton
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:文字=@字符串/分析/>
< / LinearLayout中>

顺便说一句,与亚行采取截图 - 相机正常显示。
测试的的Xperia ST27i的三星Galaxy掌上 - 同样的结果。

感谢您


解决方案

 公共无效surfaceCreated(SurfaceHolder持有人)
{
//表面有被创建,获取摄像机,并告诉它来绘制。
mCamera = Camera.open();参数PARAMS = mCamera.getParameters();如果(this.getResources()。getConfiguration()。方向!= Configuration.ORIENTATION_LANDSCAPE)
{
params.set(方向,肖像);
mCamera.setDisplayOrientation(90);
}尝试
{
mCamera.set previewDisplay(支架);
}
赶上(IOException异常除外)
{
mCamera.release();
mCamera = NULL;
}}

尝试这些code的朋友...............

I was trying to create camera app, but I have faced this issue : when using camera in landscape mode everything is OK, but using in portrait with setDisplayOrientation(90) method brings up this issue:

Half of the screen is black.

Image here: http://i.stack.imgur.com/sPTex.jpg

surfaceCreated method:

@Override
    public void surfaceCreated(SurfaceHolder holder) {
        try {
            this.camera = Camera.open();
            this.camera.setDisplayOrientation(90);
            this.camera.setPreviewDisplay(this.holder);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

My XML layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <FrameLayout
        android:id="@+id/cameraPreview"
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1" >
    </FrameLayout>
    <Button
        android:id="@+id/analyzeButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/analyze" />
</LinearLayout>

By the way, in screenshots taken with ADB - camera is shown normally. Tested on Xperia ST27i an Samsung Galaxy Pocket - same results.

Thank you

解决方案

public void surfaceCreated(SurfaceHolder holder)
{
// The Surface has been created, acquire the camera and tell it where to draw.
mCamera = Camera.open();

Parameters params = mCamera.getParameters();

if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE)
{
params.set("orientation", "portrait");
mCamera.setDisplayOrientation(90);
}

try
{
mCamera.setPreviewDisplay(holder);
}
catch (IOException exception)
{
mCamera.release();
mCamera = null;
}

}

try these code friend ......................

这篇关于Android相机 - 一半的屏幕是黑色人像模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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