Android相机与表面视图肖像

时间:2011-12-22 11:29:25

标签: android android-layout

我有一个使用相机拍照的应用程序。相机必须在相机预览上覆盖,因为用户必须将图片放在屏幕中心的圆圈中,这样我就可以使用表面视图并在相机上放置一个png图像。

我想让我的表面视图和相机进入纵向模式。

EDIT代码已更新,但现在收到错误LOGTAG cannot be resolved

public void surfaceCreated(SurfaceHolder holder) {
    // TODO Auto-generated method stub

    camera = Camera.open();
    try {
           Camera.Parameters parameters = camera.getParameters();
           if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) {
              // This is an undocumented although widely known feature
              parameters.set("orientation", "portrait");
              // For Android 2.2 and above
              //camera.setDisplayOrientation(90);
              // Uncomment for Android 2.0 and above
              //parameters.setRotation(90);
           } else {
              // This is an undocumented although widely known feature
              parameters.set("orientation", "landscape");
              // For Android 2.2 and above
              //camera.setDisplayOrientation(0);
              // Uncomment for Android 2.0 and above
              //parameters.setRotation(0);
           }
          camera.setParameters(parameters);
          camera.setPreviewDisplay(holder);
      } catch (IOException exception) {
         camera.release();
        Log.v(LOGTAG,exception.getMessage());
       }
        camera.startPreview();
    }


public void surfaceDestroyed(SurfaceHolder holder) {
    // TODO Auto-generated method stub
    camera.stopPreview();
    camera.release();
    camera = null;
    previewing = false;
}
}

1 个答案:

答案 0 :(得分:2)

使用此代码......这将解决您的问题..

 public void surfaceCreated(SurfaceHolder holder) {
      camera = Camera.open();
      try {
           Camera.Parameters parameters = camera.getParameters();
           if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) {
              // This is an undocumented although widely known feature
              parameters.set("orientation", "portrait");
              // For Android 2.2 and above
              //camera.setDisplayOrientation(90);
              // Uncomment for Android 2.0 and above
              //parameters.setRotation(90);
           } else {
              // This is an undocumented although widely known feature
              parameters.set("orientation", "landscape");
              // For Android 2.2 and above
              //camera.setDisplayOrientation(0);
              // Uncomment for Android 2.0 and above
              //parameters.setRotation(0);
           }
          camera.setParameters(parameters);
          camera.setPreviewDisplay(holder);
      } catch (IOException exception) {
         camera.release();
        Log.v(LOGTAG,exception.getMessage());
       }
        camera.startPreview();
    }
相关问题