Android - How to make a camera preview using TextureView

I have a preview, which is WpxHp, I want to take HxW pictures, so I want the user to see a preview window that has the same aspect ratio of the image that I take, and not one from the preview. How to crop a preview using TextureView?

- edit

what i thought was to use the scale matrix to distort the image so that cmpensate to resize the TextureView, let me explain better:
I have a target preview (image) whose size is (W, H). So I need to resize the TextureView to (W, H). This means distortion, which simply represents the uneven linear scaling represented by the matrix S. Therefore, if I scale the image with inv (S), before I resize the view, I have to get the same original Preview sizes (with the same aspect ratio) but with resizing TextureView, and this is equivalent to cropping. I tried and it seems to work, but I'm looking for an alternative way.

+4
source share
1 answer

The only thing I managed to do, and it works well, is to add scale.

I wanted to create a texture with part of the camera output, but I could not do this without waiting for the preview.

therefore, after I decide what is the best resolution for the camera / screen to start capture ratio, I get the zoom ratio between the camera capture height and the height I want to show.

mPreviewSize = chooseOptimalSize(...);

int viewHeight = getDP(this, R.dimen.videoCaptureHeight);
float scaleY = mPreviewSize.getHeight() / viewHeight;
setScaleY(scaleY);
0
source

All Articles