[英]android camera portrait orientation
I am using camera in my app. 我在我的应用程序中使用相机。 I am just using intent
to start camera 我只是用intent
启动相机
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(cameraIntent, 101);
The captured image automatically comes in landscape view
. 捕获的图像自动进入landscape view
。 How do i make camera
to capture images in portrait view
如何使camera
以portrait view
捕捉图像
If device has v2.2
or above you can rotate camera orientation to portrait using camera.setDisplayOrientation(90)
. 如果设备具有v2.2
或更高版本,则可以使用camera.setDisplayOrientation(90)
将摄像机方向旋转为纵向。 In devices below to v2.2 the camera will only display in landscape orientation and thus image will come in landscape. 在低于v2.2的设备中,相机仅以横向显示,因此图像将以横向显示。 Check these posts Using Camera in Portrait Orientation , Camera is wrong unless keyboard is open . 检查这些帖子在纵向方向使用相机, 除非键盘打开,否则相机错误 。
try this. 试试这个。
Parameters param = mCamera.getParameters();
switch(mDisplay.getRotation()){
case Surface.ROTATION_0:
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO){
mCamera.setDisplayOrientation(90);
Log.d("Rotation_0", "whatever");
}
else{
Log.d("Rotation_0", "whatever");
param.setRotation(90);
mCamera.setParameters(param);
}
break;
case Surface.ROTATION_90:
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO){
mCamera.setDisplayOrientation(0);
Log.d("Rotation_0", "whatever");
}
else{
Log.d("Rotation_90", "whatever");
param.setRotation(0);
mCamera.setParameters(param);
}
break;
}
Here, this code is suitable for all types of orientation that are supported in android camera application[Portrait mode] too. 这里,此代码适用于Android相机应用程序[纵向模式]中支持的所有类型的方向。
int rotation = this.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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.