簡體   English   中英

Android相機-縱向模式下半屏為黑色

[英]Android Camera - Half of the screen is black in Portrait mode

我試圖創建相機應用程序,但是遇到了這個問題:在橫向模式下使用相機時,一切都很好,但是在帶有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拍攝的屏幕截圖中-攝像機正常顯示。 在Xperia ST27i和Samsung Galaxy Pocket上進行了測試-相同的結果。

謝謝

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

}

嘗試這些代碼的朋友......................

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM