Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SurfaceTexture size, how is it defined?

I'm using SurfaceTexture to draw preview of camera and need to know the size of the texture + what happens in the process.

Let's say the supported camera preview sizes by device are:

1280 720, 1024 576, 960 720, 800 600, 800 480, 768 576, 736 552, etc..

It's obvious that there's mismatch between these sizes and standard texture sizes 2048x2048, 2048x1024, 1024x1024...

I can think of following situations that follow, but I'm uncertain:

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, surface texture is in size of selected preview size, eg 1280 x 720, but that is not pow2 format and could mean compatibility problems

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, 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.

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, surface texture is sized up to fit next pow2 texture (perhaps even sized down), image proportions are lost, and also quality suffers. eg 1920 x 1080 stretched across 2048 x 2048.

4, some other possibility?

How is the camera preview being mapped to the texture and how is the texture size defined in the end?

like image 576
Jayco Avatar asked Jun 11 '14 12:06

Jayco


1 Answers

Actually when you are previewing you have buffers that you can set to "keep" the "big" resolution.

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());
like image 189
gmetax Avatar answered Sep 20 '22 14:09

gmetax