1

I am working on an app at the moment. The client requires the camera preview to be a square. I tried this by overriding onmeasure in the surfaceview implementation and setting

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth());
}

This does not work too well, as the preview is stretched or compressed. Can anyone guide me as to what needs to be done to get a 1:1 aspect ratio. I have read about getting supported preview sizes but none of them are in the required 1:1 aspect ratio.

Rohan
  • 593
  • 7
  • 22
  • You need to cut off part of the preview -- I don't think most cameras feature a 1:1 aspect ratio mode. One approach is to feed it into OpenGL ES and render a square section of the texture; "texture from camera" in Grafika has all the bits and pieces (but doesn't do the 1:1 part). – fadden May 29 '15 at 16:07
  • e.g. http://stackoverflow.com/questions/30587291/crop-video-before-encoding-with-mediacodec-for-grafikas-continuous-capture-ac – fadden Jun 03 '15 at 00:14

0 Answers0