SurfaceTexture大小,它是如何定义的?

时间:2014-06-11 12:36:04

标签: android camera textures opengl-es-2.0

我正在使用SurfaceTexture绘制相机的预览,需要知道纹理的大小+过程中发生的事情

假设设备支持的相机预览尺寸为:

1280 720,1024 576,960 720,800 600,800 480,768 576,736 552等。

很明显,这些尺寸与标准纹理尺寸2048x2048,2048x1024,1024x1024之间存在不匹配...

我可以想到以下情况,但我不确定:

1,  surface texture is in size of selected preview size, eg 1280 x 720, but that is not pow2 format and could mean compatibility problems

1,表面纹理的大小与所选的预览尺寸相同,例如1280 x 720,但这不是pow2格式,可能意味着兼容性问题

2, surface texture is contained within next size of pow2 format, untransformed, for example 1280x720 would be contained within 2048 x 1024 texture, no stretching, part of the texture remains unused

2,表面纹理包含在pow2格式的下一个尺寸内,未转换,例如1280x720将包含在2048 x 1024纹理内,没有拉伸,部分纹理仍未使用。

3, surface texture is sized up to fit next pow2 texture (perhaps even sized down), image proportions are lost, and also quality suffers. eg 1280 x 720 stretched across 2048 x 1024.

3,表面纹理的大小适合下一个pow2纹理(可能甚至尺寸缩小),图像比例丢失,质量也受损。例如1920 x 1080横跨2048 x 2048.

4,还有其他一些可能性吗?

如何将相机预览映射到纹理以及最终如何定义纹理大小?

1 个答案:

答案 0 :(得分:4)

实际上,当您预览时,您可以将缓冲区设置为"保持" "大"分辨率。

Size mPreviewSize;

CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);

String cameraId = manager.getCameraIdList()[0];
CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);

StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
mPreviewSize = map.getOutputSizes(SurfaceTexture.class)[0];

SurfaceTexture texture = mTextureView.getSurfaceTexture();
// We configure the size of default buffer to be the size of camera
// preview we want.
texture.setDefaultBufferSize(mPreviewSize.getWidth(),mPreviewSize.getHeight());