锁定您的相机以风景模式在Android的

问题描述:

我想锁住我摄像机视图为“景观” mode.When我就简单的按钮点击我的应用程序,当时设备的摄像头将打开,并相机应锁定至“风景模式”。任何人都可以知道这个问题的解决方案?锁定您的相机以风景模式在Android的

我在“CaptureImageActivity.java”活动中使用此代码。 因此,执行此活动后,我系统的相机将打开。

btn1.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 

      Intent i=new Intent(android.provider.MediaStore. ACTION_IMAGE_CAPTURE); 
      i.putExtra(android.provider.MediaStore.EXTRA_SCREEN_ORIENTATION,ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 


      startActivityForResult(i,1000); 

     } 
    }); 

而我想锁定相机视图为“LandScape模式”。并根据解决方案

<activity android:name=".CaptureImageActivity" 
    android:screenOrientation="landscape" 
       android:label="@string/app_name"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 

只有“CaptureImageActivity”活动被锁定为“LandScape模式”。

+0

接受帮助你答案 – Shruti

添加到这一点你的活动清单文件

android:screenOrientation="portrait" 
+1

我可以用这个,如果我使用的是Android默认的相机? –

+0

我想将相机视图锁定在potraite上 – Prasad

看到这个链接来锁定您的相机方位内,使用setDisplayOrientation (int degrees)

文档可以下面的链接中找到: http://developer.android.com/reference/android/hardware/Camera.html#setDisplayOrientation%28int%29

更多详情见这个答案:

How to set Android camera orientation properly?

By using setCameraDisplayOrientation= 
public static void setCameraDisplayOrientation(Activity activity, 
     int cameraId, android.hardware.Camera camera) { 
    android.hardware.Camera.CameraInfo info = 
      new android.hardware.Camera.CameraInfo(); 
    android.hardware.Camera.getCameraInfo(cameraId, info); 
    int rotation = activity.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; 
    } 

    int result; 
    if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { 
     result = (info.orientation + degrees) % 360; 
     result = (360 - result) % 360; // compensate the mirror 
    } else { // back-facing 
     result = (info.orientation - degrees + 360) % 360; 
    } 
    camera.setDisplayOrientation(result); 
}