简体   繁体   中英

Android - How to Crop Camera Preview using TextureView

I have a preview that is WpxHp, I want to take HxW pictures, thus I want the user to see a preview window that has the same aspect ratio of the picture I'll take, not the one of the preview. How can I crop the preview using the TextureView?

-- edit

what I thought is to use a scale Matrix to distort the image so as to cmpensate for the TextureView resize, let me explain better:
I have a target preview (image) size that is (W,H). Therefore I need to resize the TextureView to (W,H). This implies a distortion that simply is a non uniform linear scaling representable by the matrix S. Therefore if I scale the image with inv(S) before resizing the view I should obtain the same original dimensions of the Preview (thus the same aspect ratio) but with the TextureView resized and this is equivalent to a crop. I tried and it seems to work, but I'm looking for an alternative way

the only that I have managed to do and it working good is to add a scale.

I wanted to create a textureview with a part of the camera output, but I couldn't do that without letting the preview to get scalled.

so after I decide what is the best resolution for the camera/screen ratio to start capturing I get the scale 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM