androidでカメラビューをランドスケープモードにロックする[複製]
-
12-12-2019 - |
質問
私は私をロックしたい カメラビュー へ"風景"モード。私のアプリでシンプルなボタンをクリックすると、その時間デバイスのカメラが開き、それが表示されます カメラはロックされるべきです へ"ランドスケープモード".誰もがこの問題の解決策を知ることができますか?
「CaptureImageActivity」内でこのコードを使用しています。java"の活動。したがって、このアクティビティを実行した後、私のシステムのカメラが開きます。
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent i=new Intent(android.provider.MediaStore. ACTION_IMAGE_CAPTURE);
i.putExtra(android.provider.MediaStore.EXTRA_SCREEN_ORIENTATION,ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
startActivityForResult(i,1000);
}
});
そして、そのカメラビューを「ランドスケープモード」にロックしたいと思います。そして解決によって
<activity android:name=".CaptureImageActivity"
android:screenOrientation="landscape"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
「Captureimageactivity」アクティビティのみが「ランドスケープモード」にロックされています。
解決
これをマニフェストファイル内のアクティビティに追加します
android:screenOrientation="portrait"
他のヒント
あなたのカメラの向きをロックするには、このリンクを参照してくださ setDisplayOrientation (int degrees)
ドキュメントは次のリンクにあります :http://developer.android.com/reference/android/hardware/Camera.html#setDisplayOrientation%28int%29
詳細については、この回答を参照してください :
By using setCameraDisplayOrientation=
public static void setCameraDisplayOrientation(Activity activity,
int cameraId, android.hardware.Camera camera) {
android.hardware.Camera.CameraInfo info =
new android.hardware.Camera.CameraInfo();
android.hardware.Camera.getCameraInfo(cameraId, info);
int rotation = activity.getWindowManager().getDefaultDisplay()
.getRotation();
int degrees = 0;
switch (rotation) {
case Surface.ROTATION_0: degrees = 0; break;
case Surface.ROTATION_90: degrees = 90; break;
case Surface.ROTATION_180: degrees = 180; break;
case Surface.ROTATION_270: degrees = 270; break;
}
int result;
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
result = (info.orientation + degrees) % 360;
result = (360 - result) % 360; // compensate the mirror
} else { // back-facing
result = (info.orientation - degrees + 360) % 360;
}
camera.setDisplayOrientation(result);
}
所属していません StackOverflow