如何拍摄人像照片时,设备处于景观 [英] How to take a portrait photo when device is in landscape

查看:308
本文介绍了如何拍摄人像照片时,设备处于景观的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为其物理总是在横向举行的设备相当专业的相机应用。该规范的部分原因是,它必须可选择能preVIEW和拍照的纵向 - 看配置'A'下面。

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.

(现在才有人票关闭这个问题,暗示这是<一个重复href=\"http://stackoverflow.com/questions/25549561/any-problems-taking-a-portrait-photo-when-device-is-in-landscape\">this其他SO质疑,让我指出,另一个问题只是解决的是否的有可能还是不 - 到所要求的答案是肯定的这个问题,是关于的怎么的是可以做到的。)

(Now before anyone votes to close this question suggesting this is a repeat of this other SO question, let me point out that the other question merely addressed whether it was possible or not - to which the claimed answer is yes. This question, is about how it can be done.)

我已经设置为preVIEW一个TextureView并呼吁camera.set previewTexture(),所以我看到相机的屏幕上的图像。我也有code启动并运行它做什么,我需要的风景版本,请参阅配置B的下方。

I have already set up a TextureView for the preview and called camera.setPreviewTexture(), so I see the camera's image on screen. I also have code up and running which does the landscape version of what I require, see configuration 'B' below.


为了设置相机参数,我首先用getParameters(),然后修改只是我想改变那些读相机的自己的设置。因此,在配置'B'的情况下,它仅仅是一个执行以下code的事情:

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);

编辑:我已经检查了640×480是同时适用于preVIEW和图像大小)。
该应用程序,然后工作工程完全按照我期望的那样。

( I already checked that 640x480 was available for both preview and picture sizes). The app then works works exactly as I would expect.

试图获得配置A时,问题就来。这一次,我设置纹理以更宽比它高,并执行以下code:

The problem comes when attempting to get configuration 'A' working. This time, I set the texture view to be wider than it is tall, and execute the following code:

camera_parameters = camera.getParameters();
camera_parameters.set("orientation", "portrait");
camera_parameters.setPreviewSize(640,480); 
camera_parameters.setPictureSize(640,480); 
camera.setParameters(camera_parameters);

可惜,这并不完全做的工作。我到底是什么了,当应用程序运行时看起来更像是这样的:

正如你可以看到在这个preVIEW显示的图像基本上是宽度大于高,已经变形为一个矩形,高度大于宽的图像。由此产生的保存的JPEG图像文件也更宽比它高。

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.

我想也许我需要改变code以下内容:

I thought that perhaps I needed to change the code to the following:

camera_parameters = camera.getParameters();
camera_parameters.set("orientation", "portrait");
camera_parameters.setPreviewSize(480,640); 
camera_parameters.setPictureSize(480,640); 
camera.setParameters(camera_parameters);

但是,这会导致异常setParameters失败。

But this causes an exception "setParameters failed".

所以我的问题是,我应该是什么样的参数设置什么样的价值观, camera.getParameters()之间; setParameters(camera_parameters);

So my question is, what parameters should I be setting to what values, between camera.getParameters(); and setParameters(camera_parameters); ?

推荐答案

我工作了很多相机和照片,以实现类似的应用程序脸洞
在这种情况下,问题是,你尝试以绝对值设定的大小。

i work a lot with camera and picture to realize an application similar to "face in hole" In this case the problem is that you try to set the size with absolute value.

 camera_parameters.setPreviewSize(480,640);
 camera_parameters.setPictureSize(480,640); 

这可以在您的电话/仿真器抛出异常,并在另一个可以很好地工作。问题是,你必须阅读允许的大小(相关型号相机),并创建一个算法在它们之间做出选择。
该功能是:

This can throw exception on your phone/emulator and in another can work well. The problem is that you must read the allowed size ( releated to the camera ) and create an algorithm to choose between them. The functions are:


  1. Camera.Parameters.getSupportedPictureSizes()

  2. Camera.Parameters.getSupported previewSizes()

  1. Camera.Parameters.getSupportedPictureSizes()
  2. Camera.Parameters.getSupportedPreviewSizes()

在这里,你可以找到一个很简单的例子:

Here you can find a very simple example:

 mCamera = Camera.open();
 Camera.Parameters params = mCamera.getParameters();
 List<Size> sizes = params.getSupportedPictureSizes();
 // See which sizes the camera supports and choose one of those
 mSize = sizes.get(0);
 params.setPictureSize(mSize.width, mSize.height);
 mCamera.setParameters(params);

有了这个提示,你可以找到最适合您的期望的解决方案。

With this tips you can find the solution that best fit your expectation.

这篇关于如何拍摄人像照片时,设备处于景观的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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