我尝试了几种方法来尝试让相机预览以纵向方式显示在 SurfaceView. 。什么都没起作用。我正在使用 2.0.1 的 Droid 进行测试。我试过:

1)通过以下方式强制布局为纵向: this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

2)使用

Camera.Parameters parameters = camera.getParameters();
parameters.set("orientation", "portrait");
parameters.setRotation(90);
camera.setParameters(parameters);

我还有什么可以尝试的吗?如果这是 Android 或手机中的错误,我如何确保确实如此,以便我有证据通知客户?

谢谢,普拉萨娜

没有正确的解决方案

其他提示

API LVL 8的作为,这是可用的:

公共最终空隙setDisplayOrientation(INT度)

即。与在清单波泰特:

public void surfaceCreated(SurfaceHolder holder) {
    mCamera = Camera.open();
    mCamera.setDisplayOrientation(90);

我有纵向模式在2.1(上欲测试)工作工作溶液也许更小。

活动屏幕方向设置为肖像。 (机器人:screenOrientation = “纵向”)

相机参数:

Camera.Parameters P = mCamera.getParameters();

 p.set("jpeg-quality", 100);
 p.set("orientation", "landscape");
 p.set("rotation", 90);
 p.setPictureFormat(PixelFormat.JPEG);
 p.setPreviewSize(h, w);// here w h are reversed
 mCamera.setParameters(p);

和图像将是人像。

您使用的相机SurfaceHolder必须在一个大小与手机预览大小兼容 usualy屏幕分辨率。

滑稽上欲望2.2是不工作... 这里是修正:

   At surfaceCreated(..) or when you have this line
camera = Camera.open();
       add
camera.setDisplayOrientation(90);//only 2.2>

Camera.Parameters p = camera.getParameters();
    p.set("jpeg-quality", 100);
p.setRotation(90);
p.setPictureFormat(PixelFormat.JPEG);
p.setPreviewSize(h, w);
camera.setParameters(p);

您可以试试这个(好2.2或以下)。在这里,我将其保存到SD卡之前,旋转图像。但它仅适用于纵向模式。如果你必须让两个模式,那么你应该检查相机的方向和捕捉图像之前把一些检查。

PictureCallback jpegCallback = new PictureCallback() {
   public void onPictureTaken(byte[] data, Camera camera) {
      FileOutputStream outStream = null;
      try {
        imageFilePath = getFilename();
        InputStream is = new ByteArrayInputStream(data);
        Bitmap bmp = BitmapFactory.decodeStream(is);
        // Getting width & height of the given image.
        if (bmp != null){
           int w = bmp.getWidth();
           int h = bmp.getHeight();
           // Setting post rotate to 90
           Matrix mtx = new Matrix();
           mtx.postRotate(90);
           // Rotating Bitmap
           Bitmap rotatedBMP = Bitmap.createBitmap(bmp, 0, 0, w, h, mtx, true);
           ByteArrayOutputStream stream = new ByteArrayOutputStream();
           rotatedBMP.compress(Bitmap.CompressFormat.PNG, 100, stream);
           byte[] byteArray = stream.toByteArray(); 
           outStream = new FileOutputStream
                              (String.format(imageFilePath,System.currentTimeMillis()));
           outStream.write(byteArray);
           outStream.close();
        } else {
           outStream = new FileOutputStream
                              (String.format(imageFilePath,System.currentTimeMillis()));
           outStream.write(data);
           outStream.close();           
        }       

        preview.camera.startPreview();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
    }
  }
};

目前的许多设备(包括 G1 和 Droid)都无法做到这一点。在这里查看相关的错误报告:

另请参阅此处 Android 工程师之一 (Dave) 的评论:

罗马给了问题线程的链接有一个可行的解决方案,我使用了。

在这里找到: http://code.google.com/p/android/issues /细节?ID = 1193#C26

有没有必要你,直到你需要做的,明确设定为取向的任何参数。默认情况下,它支持这一设施。就我而言,我有一个活动,并且活动上面,我有一个摄像头视图,所以我没有设置相机性能的任何方向,而不是为我设定的方向在清单文件肖像的活动。现在的应用程序的外观和做工不错。可能对某些一个有用..

感谢。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top