4

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

LJSilver
  • 583
  • 7
  • 20
  • 1
    You can see an example of manipulating the camera preview in Grafika -- see "texture from camera" activity. https://github.com/google/grafika – fadden Aug 27 '14 at 16:04
  • thanks for the hint! it is very interesting. However it doesn't use the TextureView component and it seems not tu crop anything, it instead searches for a match in the supported preview sizes – LJSilver Aug 27 '14 at 17:13
  • Use the sliders to "zoom". It's effectively cropping the source image, and scaling it up to match the current frame size. TextureView vs. SurfaceView isn't really relevant; it's just GLES output. – fadden Aug 27 '14 at 20:29
  • @mb_ did you find the solution ? because I'm facing the same issue but didn't able to produce results. If you have found the solution then kindly share it with us. Thank you. – Bilal Rabbani Dec 11 '14 at 10:19

1 Answers1

0

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);
gmetax
  • 3,853
  • 2
  • 31
  • 45