在我的 Android 应用程序中,我正在使用Android default camera
为此,我使用了下面的代码。捕获照片后,我已以全屏模式将该图像显示到另一个活动中。如果我捕获图像portrait
模式 我可以将整个图像设置为全屏模式。它显示良好,显示图像后我可以执行我的操作。但是如果我从landscape
拍摄的图像将在屏幕上拉伸。所以我想仅使用肖像模式而不是风景模式来拍摄照片。那么我如何才能锁定相机应用程序仅用于肖像。
String fileName = "Camera_Example.jpg";
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, fileName);
values.put(MediaStore.Images.Media.DESCRIPTION,"Image capture by camera");
imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
intent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION,ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
startActivityForResult(intent,CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
AndroidManifest.xml
<activity
android:name=".TestActivity"
android:screenOrientation="portrait"
android:configChanges="orientation"
android:theme="@android:style/Theme.NoTitleBar" >
</activity>
portrait captured photo![enter image description here](https://i.stack.imgur.com/YpDP4.png)
portrait captured photo full screen![enter image description here](https://i.stack.imgur.com/A1AeX.png)
landscape captured photo![enter image description here](https://i.stack.imgur.com/gbol9.png)
landscape captured photo full screen![enter image description here](https://i.stack.imgur.com/QoXzG.png)
如何锁定相机应用程序仅用于肖像
你不知道。您没有编写相机应用程序,因为有数百甚至数千个相机应用程序。由相机应用程序和用户来处理方向。
Besides:
在许多设备上,您在纵向模式下都会遇到同样的问题
你的风景照片似乎也被拉伸了,尽管没有那么严重
但如果我从风景中拍摄一张照片,所拍摄的图像将在屏幕上拉伸
您有一个,也许还有两个问题:
你没有考虑到方向photo,因此您正在加载一张风景照片,就好像它是肖像照片一样。
Your ImageView
,或者它的父级,可能配置错误。如果你想保持照片的纵横比,and你想要那个ImageView
来填充一些区域,然后ImageView
需要具有相同的纵横比。
If you really只想以肖像模式拍照,您需要使用android.hardware.Camera
除了解决我上面提到的问题之外,您自己,而不是启动第三方相机应用程序。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)