I am making a rather specialist camera app for a device which is physically always going to be held in a landscape orientation. Part of the spec is that it must optionally be able to preview and take photos in a portrait orientation - see configuration 'A' below.
(现在,在有人投票结束这个问题之前,表明这是重复的这另一个问题 https://stackoverflow.com/questions/25549561/any-problems-taking-a-portrait-photo-when-device-is-in-landscape,让我指出另一个问题只是解决whether可能或不可能——声称的答案是肯定的。这个问题,是关于how可以办到。)
我已经为预览设置了一个TextureView并调用了camera.setPreviewTexture(),所以我在屏幕上看到了相机的图像。我还启动并运行了代码,该代码执行我所需要的横向版本,请参阅下面的配置“B”。
In order to set up the camera parameters, I first of all read the camera's own settings using getParameters(), then modify just the ones I want to change. So in the case of configuration 'B', it is just a matter of executing the following code:
camera_parameters = camera.getParameters();
camera_parameters.setPreviewSize(640,480);
camera_parameters.setPictureSize(640,480);
camera.setParameters(camera_parameters);
(EDIT:我已经检查过 640x480 可用于预览和图片尺寸)。
然后该应用程序就可以完全按照我的预期运行。
当尝试让配置“A”工作时就会出现问题。这次,我将纹理视图设置为宽大于高,并执行以下代码:
camera_parameters = camera.getParameters();
camera_parameters.set("orientation", "portrait");
camera_parameters.setPreviewSize(640,480);
camera_parameters.setPictureSize(640,480);
camera.setParameters(camera_parameters);
Unfortunately this does not quite do the job. What I end up with when the app runs looks more like this:
As you can see the image displayed in this preview is essentially an image that is wider than it is tall, that has been deformed into a rectangle that is taller than it is wide. The resulting saved jpeg image file is also wider than it is tall.
我想也许我需要将代码更改为以下内容:
camera_parameters = camera.getParameters();
camera_parameters.set("orientation", "portrait");
camera_parameters.setPreviewSize(480,640);
camera_parameters.setPictureSize(480,640);
camera.setParameters(camera_parameters);
但这会导致异常“setParameters failed”。
所以我的问题是,我应该将哪些参数设置为哪些值camera.getParameters();
and setParameters(camera_parameters);
?