How to set Android default camera app for portrait orientation only

孤街浪徒 提交于 2019-12-02 12:49:41

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.

Besides:

  • 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. You are not taking into account the orientation of the photo, and so you are loading a landscape photo as if it were portrait.

  2. 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.

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.

karim saad

Try 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();
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!