Camera2 1440x1080最大 [英] Camera2 1440x1080 is maximum

查看:152
本文介绍了Camera2 1440x1080最大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Camera2以横向(1920x1080)显示普通的全高清预览,但是相机返回的分辨率是1440x1080.

I'm trying to display normal Full HD preview in landscape orientation (1920x1080) using Camera2, but camera returns 1440x1080 as the highest resolution.

使用传统相机(android.hardware.camera),同一设备没有出现此类问题.我在做什么错了?

With Legacy Camera (android.hardware.camera) there was no such issue for the same device. What am I doing wrong?

CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
cameraId = manager.getCameraIdList()[0];
CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);
StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
assert map != null;
imageDimension = map.getOutputSizes(SurfaceTexture.class)[0];

for (Size size : map.getOutputSizes(SurfaceTexture.class)) {
    Log.i(TAG, "imageDimension " + size);
}

输出:

imageDimension 1440x1080
imageDimension 1280x960
imageDimension 1280x720
imageDimension 864x480
imageDimension 640x640
imageDimension 832x486
imageDimension 800x480
imageDimension 720x480
imageDimension 768x432
imageDimension 640x480

另外,要正确显示横向预览效果,我们还需要很多令人头疼的代码,例如:

Also it seems that to correctly display preview in landscape we need a lot of headache code like:

private void configureTransform(int viewWidth, int viewHeight) {
        Activity activity = getActivity();
        if (null == mTextureView || null == mPreviewSize || null == activity) {
            return;
        }
        int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
        Matrix matrix = new Matrix();
        RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
        RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
        float centerX = viewRect.centerX();
        float centerY = viewRect.centerY();
        if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
            bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
            matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
            float scale = Math.max(
                    (float) viewHeight / mPreviewSize.getHeight(),
                    (float) viewWidth / mPreviewSize.getWidth());
            matrix.postScale(scale, scale, centerX, centerY);
            matrix.postRotate(90 * (rotation - 2), centerX, centerY);
        } else if (Surface.ROTATION_180 == rotation) {
            matrix.postRotate(180, centerX, centerY);
        }
        mTextureView.setTransform(matrix);
    }

摘自官方示例 Camera2是否应该使事情比传统相机更轻松?我不确定...

Isn't Camera2 supposed to make things easier than legacy camera? I'm not sure...

虽然我看到了一件好事:我们可以设置许多表面目标,但是对于传统相机,我们不能同时使用setPreviewDisplaysetPreviewTexture,但是Camera2可以提供许多输出

Though one good thing I see: we can set many surface targets, with legacy camera we could not use setPreviewDisplay and setPreviewTexture together, but Camera2 allows many outputs

更新

天哪!

接下来的消息震惊了我

p.s.我已经在小米设备上进行了测试

p.s. I have tested on Xiaomi device

Android Camera2输出大小

https://github.com/googlesamples/android-Camera2Basic/issues/113

https://github.com/googlesamples/android-Camera2Basic/issues/123

推荐答案

TL; DR 如果您拥有CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY,则基本上您的电话制造商不支持Camera API2.

TL;DR If you have CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY basically your phone manufacturer does not support Camera API2.

对于那些像我一样来到这里的人,您可以在相关的问题和此 github问题.

For those who end up here as I did you can find the explanation in this related question and this github issue .

这篇关于Camera2 1440x1080最大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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