0

カメラアプリを作成しようとしましたが、この問題に直面しました。カメラを横向きモードで使用するとすべて問題ありませんが、縦向きでsetDisplayOrientation(90)メソッドを使用すると次の問題が発生します。

画面の半分が黒です。

ここの画像:http://i.stack.imgur.com/sPTex.jpg

surfaceCreatedメソッド:

@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();
        }
    }

私のXMLレイアウト

<?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>

ちなみに、ADBで撮影したスクリーンショットでは、カメラは正常に表示されています。XperiaST27iでSamsungGalaxyPocketをテストしました-同じ結果です。

ありがとうございました

4

1 に答える 1

0
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;
}

}

これらのコードの友達を試してください .................................

于 2013-01-30T10:46:45.797 に答える