如何在android摄像头中交换预览大小的宽度和高度?
我们可以通过指定预览大小打开android camera,例如:如何在android摄像头中交换预览大小的宽度和高度?,android,camera,android-camera,Android,Camera,Android Camera,我们可以通过指定预览大小打开android camera,例如: mParameter.setPreviewSize(640, 480); mCamera.setParameter(mParameter); 上述比率为1.3333 有没有办法交换宽度和高度?也就是说,效果是这样的: mParameter.setPreviewSize(480, 640); mCamera.setParameter(mParameter); 比率为0.75并非所有设备都支持所有视频预览大小。您只能通过编程来完成
mParameter.setPreviewSize(640, 480);
mCamera.setParameter(mParameter);
上述比率为1.3333
有没有办法交换宽度和高度?也就是说,效果是这样的:
mParameter.setPreviewSize(480, 640);
mCamera.setParameter(mParameter);
比率为0.75并非所有设备都支持所有视频预览大小。您只能通过编程来完成如果大小不适用,则抛出媒体录制器停止-19错误
int width = 320;
int height = 240;
try {
//get the available sizes of the video
List<Size> tmpList = getSupportedVideoSizes();
final List<Size> sizeList = new Vector<Size>();
// compare the apsect ratio of the candidate sizes against the
// real ratio
Double aspectRatio = (Double.valueOf(getWindowManager()
.getDefaultDisplay().getHeight()) / getWindowManager()
.getDefaultDisplay().getWidth());
for (int i = tmpList.size() - 1; i > 0; i--) {
Double tmpRatio = Double.valueOf(tmpList.get(i).height)
/ tmpList.get(i).width;
if (EnableLog.LOG_TAG) {
Log.e("Width & height", tmpList.get(i).width + " x "
+ tmpList.get(i).height);
}
if (Math.abs(aspectRatio - tmpRatio) < .15) {
width = tmpList.get(i).width;
height = tmpList.get(i).height;
sizeList.add(tmpList.get(i));
}
}
if (EnableLog.LOG_TAG) {
Log.e("tmpList", tmpList + "*");
}
} catch (Exception e) {
e.printStackTrace();
}
// set the size of video.
// If the size is not applicable then throw the media recorder stop
// -19 error
mrec.setVideoSize(width, height);
/**
* This method will return the size of the video
*
* if the getSupportedVideoSizes() is return null
*
* then it is possible to get the size of video from
* getSupportedPreviewSizes()
*
* @return list of size
*/
public List<Size> getSupportedVideoSizes() {
if (params.getSupportedVideoSizes() != null) {
return params.getSupportedVideoSizes();
} else {
// Video sizes may be null, which indicates that all the supported
// preview sizes are supported for video recording.
return params.getSupportedPreviewSizes();
}
}
到
for(int i=0;i
这将为您提供更好的预览大小。并非所有设备都支持所有视频预览大小。您只能通过编程来完成如果大小不适用,则抛出媒体录制器停止-19错误
int width = 320;
int height = 240;
try {
//get the available sizes of the video
List<Size> tmpList = getSupportedVideoSizes();
final List<Size> sizeList = new Vector<Size>();
// compare the apsect ratio of the candidate sizes against the
// real ratio
Double aspectRatio = (Double.valueOf(getWindowManager()
.getDefaultDisplay().getHeight()) / getWindowManager()
.getDefaultDisplay().getWidth());
for (int i = tmpList.size() - 1; i > 0; i--) {
Double tmpRatio = Double.valueOf(tmpList.get(i).height)
/ tmpList.get(i).width;
if (EnableLog.LOG_TAG) {
Log.e("Width & height", tmpList.get(i).width + " x "
+ tmpList.get(i).height);
}
if (Math.abs(aspectRatio - tmpRatio) < .15) {
width = tmpList.get(i).width;
height = tmpList.get(i).height;
sizeList.add(tmpList.get(i));
}
}
if (EnableLog.LOG_TAG) {
Log.e("tmpList", tmpList + "*");
}
} catch (Exception e) {
e.printStackTrace();
}
// set the size of video.
// If the size is not applicable then throw the media recorder stop
// -19 error
mrec.setVideoSize(width, height);
/**
* This method will return the size of the video
*
* if the getSupportedVideoSizes() is return null
*
* then it is possible to get the size of video from
* getSupportedPreviewSizes()
*
* @return list of size
*/
public List<Size> getSupportedVideoSizes() {
if (params.getSupportedVideoSizes() != null) {
return params.getSupportedVideoSizes();
} else {
// Video sizes may be null, which indicates that all the supported
// preview sizes are supported for video recording.
return params.getSupportedPreviewSizes();
}
}
到
for(int i=0;i
这将为您提供更好的预览大小。当然欢迎您在这里调用
setPreviewSize()
,但许多设备可能会崩溃,并说这不是受支持的预览大小。@commonware是的。它将在许多设备中崩溃。那么,有没有办法实现与第二种效果相同的效果呢?您可以尝试对预览曲面使用TextureView
,并将矩阵应用到TextureView
,以旋转预览帧。虽然您当然欢迎调用setPreviewSize()
,但预计许多设备会崩溃,表示这不是受支持的预览大小。@Commonware是。它将在许多设备中崩溃。那么有没有办法实现与第二种效果相同的效果呢?您可以尝试对预览曲面使用TextureView
,并将矩阵应用到TextureView
以旋转预览帧。否。我不是要找到一种匹配最佳预览大小的方法,而是在交换宽度和高度后实现效果。此代码将设置最低预览大小,以便将for循环更改为最佳预览大小。我会更新我的问题。检查我的编辑。否。我不是要找到一种匹配最佳预览大小的方法,而是在交换宽度和高度后实现效果。此代码将设置最低预览大小,以便将for循环更改为最佳预览大小。我会更新我的问题。检查我的编辑。
for (int i = 0 ; i < tmpList.size()-1; i++) {
}