0

So, I've downloaded CWAC2 library and hacked it a bit so i can display a custom layout around the Preview of the camera.

The thing is that when I have the CameraFragment in preview mode inside a FrameLayout in my Activity (left side), i see one thing. After I take the picture (call the take appropriate method from the CameraFragment) and display the image inside an ImageView I see a "larger picture" (right side).

Is there to limit the camera to only capture what it displays on the Preview? I'm guessing I need to set the aspect ratio of the .... camera ?!

And no, it's not a matter of the left side being zoomed in.

enter image description here

AndreiBogdan
  • 10,858
  • 13
  • 58
  • 106
  • "I've downloaded CWAC2 library and hacked it a bit so i can display a custom layout around the Preview of the camera" -- I recommend that you stop using this library and use the camera APIs directly. Basically, if you have to "hack the library", you should not be using the library. The library is a replacement for `ACTION_IMAGE_CAPTURE`, **and that's it**. – CommonsWare May 18 '16 at 18:19
  • "Is there to limit the camera to only capture what it displays on the Preview?" -- There is no requirement for a camera picture to exactly match the content of a camera preview. The hardware is welcome to do whatever it wants. The unhacked CWAC-Cam2 library crops the preview to be able to fill the screen with the cropped preview. Since the preview aspect ratio has nothing much to do with the picture aspect ratio, and since the screen aspect ratio has nothing much to do with the picture aspect ratio, the picture may show more than what is visible to the user in the preview. – CommonsWare May 18 '16 at 18:19

1 Answers1

0

As far as I understood, you would need to change what the CameraView is sending to your Frame Layout, so it's displaying the same thing as the camera is getting (your right pic).

Inside adjustAspectRatio() from the CameraView.java, try playing with the scaling of the view.

  txform.setRectToRect(rectView, rectPreview, Matrix.ScaleToFit.START); // or Matrix.ScaleToFit.CENTER

  float scale=Math.max((float)yourFrameLayoutHeight/rectPreview.height(), (float)yourFrameLayoutWidth/rectPreview.width());
  txform.postScale(scale, scale, viewCenterX, viewCenterY);