如何将Android默认相机应用设置为仅纵向显示 [英] How to set Android default camera app for portrait orientation only

查看:176
本文介绍了如何将Android默认相机应用设置为仅纵向显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的android应用程序中,我为此使用Android default camera捕获照片,我使用了下面的代码.捕获照片后,我已将Image显示为全屏模式下的另一个活动.如果我以portrait模式捕获了图像我可以将整个图像设置为全屏模式.显示完图像后,它可以显示图像,可以执行我的操作.但是,如果我从landscape捕获了照片,则所拍摄的图像将在屏幕上拉伸设置.因此我只想在不使用风景的情况下使用肖像模式拍摄照片.因此,如何锁定仅用于人像的相机应用程序.

In my android application I am capturing photo using Android default camera for this purpose I have used below code.after captured a photo I have shown that Image into another activity in full screen mode.if I captured image in portrait mode I can set the whole image into full screen mode. it showed good, after showed a image I can perform my operation.But if I captured a photo from landscape the taken image would set in screen with stretched. so I would like to capture photo using portrait mode only not in landscape. so how may I lock camera app only for portrait.

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>

肖像拍摄的照片

人像全屏拍摄的照片

拍摄的风景照

全屏捕获的风景照片

推荐答案

我该如何仅将相机应用锁定为人像模式

how may I lock camera app only for portrait

你不知道.您没有编写相机应用程序,因为有成百上千个相机应用程序.相机应用和用户可以自行决定方向.

You don't. You did not write the camera app, as there are hundreds, perhaps thousands, of camera apps. It is up to the camera app and the user to handle orientation.

此外:

  • 在许多设备上,您在纵向模式下也会遇到相同的问题

  • on many devices, you will have the same problem in portrait mode

您的风景照片也似乎被拉长了,尽管没有那么剧烈

your landscape photo also appears to be stretched, though not as drastically

但是,如果我从风景中捕获照片,则所拍摄的图像将在屏幕上拉伸设置

But if I captured a photo from landscape the taken image would set in screen with stretched

您有一个,也许有两个问题:

You have one, and perhaps two, problems:

  1. 您没有考虑照片的方向,因此您正在加载风景照片,就像它是肖像照片一样.

  1. You are not taking into account the orientation of the photo, and so you are loading a landscape photo as if it were portrait.

您的ImageView或它的父级可能配置错误.如果要保持照片的长宽比,并且希望ImageView填充某些区域,则ImageView需要具有相同的长宽比.

Your ImageView, or perhaps its parent, is probably misconfigured. If you want to maintain the aspect ratio of the photo, and you want that ImageView to fill some area, then the ImageView needs to have that same aspect ratio.

如果您真的只想以人像模式拍照,除了解决我提到的问题之外,您还需要自己使用android.hardware.Camera而不是启动第三方相机应用程序以上.

If you really want to only take photos in portrait mode, you would need to use android.hardware.Camera yourself, rather than launching a third-party camera app, in addition to addressing the problems I mention above.

这篇关于如何将Android默认相机应用设置为仅纵向显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆