摄像头显示不保持纵横比/似乎倾斜 [英] Camera display doesn't maintain aspect ratio/seems skewed

查看:150
本文介绍了摄像头显示不保持纵横比/似乎倾斜的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行到一个问题,在Android摄像头输入。搜索在互联网上半天后,我没有得到任何进一步的。

I'm running into an issue with camera input in Android. After searching over the internet for half a day I'm not getting any further.

笏我想实现这个阶段是正确显示当前摄像机输入。没有更多的也不少,现在。拿着设备时,在横向模式下,一切似乎罚款。但是当我打开设备为纵向显示似乎是横向扩展,以匹配屏幕宽度的设备上。

Wat I want to achieve at this stage is correctly displaying the current camera input. Nothing more and nothing less for now. When holding the device in landscape mode, all seems fine. However as soon as I switch the device to portrait the display seems to be horizontally scaled in order to match the width of the screen on the device.

为了澄清这个问题有点多,我已经把它贴了两张照片:

In order to clarify this issue a bit more, I've attached two photographs:

  • Landscape (looks correct)
  • Portrait (looks incorrect)

这似乎是这个问题也发生在API的例子相机的例子,但它似乎并没有出现,当我使用的摄像头应用程序从我的设备。所以很明显别的事情发生在那里。

It seems like this issue also occurs with the camera example from the API examples, but it doesn't seem to occur when I use the camera application from my device. So clearly something else is happening there.

这是我使用的是基于可以发现在互联网上例中的code没有修改:

The code that I'm using is based on examples that can be found over the internet and has no modifications:

class Preview extends SurfaceView implements SurfaceHolder.Callback {
    SurfaceHolder mHolder;
    Camera mCamera;

    Preview(Context context) {
        super(context);
        mHolder = getHolder();
        mHolder.addCallback(this);
        mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }

    public void surfaceCreated(SurfaceHolder holder) {
        mCamera = Camera.open();
        try {
            mCamera.setPreviewDisplay(holder);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public void surfaceDestroyed(SurfaceHolder holder) {
        mCamera.stopPreview();
        mCamera = null;
    }

    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
        Camera.Parameters parameters = mCamera.getParameters();
        parameters.setPreviewSize(w, h);
        mCamera.setParameters(parameters);
        mCamera.startPreview();
    }
}

该API的例子使用的方法getOptimal previewSize(...),这听起来像我所需要的方法,但是这不会改变任何东西。我离开了这里,以便尽量简短。

The API examples make use of a method "getOptimalPreviewSize(...)" which sounds like the method I need, but that does not change anything. I left it out here in order to be as brief as possible.

我失去了一些东西明显的或者这是预期的行为?

Am I missing something obvious or is this the expected behavior?

希望有人能在正确的方向指向我。

Hopefully someone can point me in the correct direction.

在此先感谢!

推荐答案

好吧,我只是找到了答案,我自己的问题。 我解决的方式是通过进入全屏我的应用程序:

Okay, I just found the answer to my own question. The way I solved it was by going fullscreen with my application:

requestWindowFeature(Window.FEATURE_NO_TITLE);

这使的感觉一点点,因为我想我们不能只使用任何分辨率的相机上的preVIEW大小。我想这会在内部捕捉到最近允许分辨率/高宽比,它不会做任何智能像裁剪图像要求的分辨率相匹配,同时保持宽高比。在我来说,我是显示一个标题栏,而源图像是全屏,然后缩小以适合屏幕上。

This makes a little bit of sense, as I guess we can not use just any resolution as the preview size on the camera. I guess it will internally snap to the closest allowed resolution/aspect ratio and it doesn't do any smart things like cropping the image to match the requested resolution while maintaining aspect ratio. In my case I was displaying a title bar while the source image was fullscreen and then downsized to fit on the screen.

我认为这是一种愚蠢的宽高比不会保持和图像默认情况下不裁剪,

I think it is kind of stupid that the aspect ratio is not maintained and images are not cropped by default,

这篇关于摄像头显示不保持纵横比/似乎倾斜的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆