锁定您的相机视图到横向模式在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