How to set default camera app for Android for portrait orientation only

In my Android application, I am taking pictures using the Android default camera for this purpose. I used below code. After I took the photo, I showed that the image is in another action in full screen. If I captured the image in portrait mode, I can set the entire image to full screen. he showed good, after showing the image I can perform my operation. But if I captured a photo with landscape , then the taken image will be installed on the screen with a stretched one. therefore, I would like to take photos using portrait mode, but not in the landscape. since I can block the camera app for portrait only.

 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 taken enter image description here

portrait shot photo full screen enter image description here

landscape shot photo enter image description here

full-screen landscape enter image description here

0
android android-orientation android-camera-intent
source share
2 answers

how to lock the camera app for portrait only

Not. You have not written a camera app, as there are hundreds, perhaps thousands, of camera apps. It depends on the application of the camera and the user on the orientation.

Besides:

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

  • Your landscape photo also looks stretched, although not so dramatically

But if I captured a photo from the landscape, then the taken image will be installed on the screen with a stretched

You have one and possibly two problems:

  • You do not take into account the orientation of the photograph, and therefore you load the landscape as if it were a portrait.

  • Your ImageView , or possibly its parent, is probably misconfigured. If you want to keep the aspect ratio of the photo and want ImageView fill in some area, then ImageView should have the same aspect ratio.

If you really want to take photos only in portrait mode, you will need to use android.hardware.Camera yourself, and not launch a third-party camera application, in addition to solving the problems that I mentioned above.

+2
source share

Try using the following code to rotate the camera:

 @Override public void surfaceCreated(SurfaceHolder surfaceHolder) { camera = Camera.open(); camera.setDisplayOrientation(90); // camera portrait oriantation try { camera.setPreviewDisplay(holder); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } 
-one
source share

All Articles