2

I've been fighting for a while with https://github.com/commonsguy/cwac-camera

Managed to create my custom CameraFragment and a custom custom CameraHost.

I've overrode getPictureSize and getPreviewSize. With those two methods I'm able to find out which Sizes are able to be used. My overall idea is to capture a square image, and also preview it before capturing.

I've been testing and no device is returning a square-formatted Size, so I guess the best approach would be taking the Size nearest to my needs. Like if I need an 800x800 squared image, I will return the nearest Size, that would be (for example) 1280x1024

So far so good. The issue is the following:

Documentation states:

Usually, your CameraHost will be called with getPreviewSize()

Damn; my Nexus5 device never triggers this method, but a Genymotion emulator does. So in my emulator I can create a custom preview size, which I can't with my real device. So I need some help with this issue. Why is it just "usually"? What can I do to change it to "always"?

On a second term, I need some tips: If I want an squared preview size, which I know it won't be available by default Sizes returned by getSupportedPreviewSizes, what can I do to display an square? Maybe overlaying a square on top of CameraFragment? Is it even possible? Or should I go for any other approach?

Anyways, congratulations on the library; it's absolutely clear and with so many options. No need to worry about "some devices". That's great as an Android Developer.

Thank you.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
Reinherd
  • 5,476
  • 7
  • 51
  • 88

1 Answers1

3

Why is it just "usually"? What can I do to change it to "always"?

Quoting the documentation:

If getRecordingHint() returns ANY or VIDEO_ONLY, though, CameraHost supplies the preview size via getPreferredPreviewSizeForVideo() instead of getPreviewSize(). If you wish to use a different preview size for video, return it, otherwise return null and we will use the results from getPreviewSize() instead.

On API Level 11+, the implementation of SimpleCameraHost getPreferredPreviewSizeForVideo() delegates to the getPreferredPreviewSizeForVideo() implementation on Camera.Parameters, except for devices known to return poor values for it.

what can I do to display an square? Maybe overlaying a square on top of CameraFragment?

I would try putting CameraView directly in your own UI, then layering something on top of it, using a FrameLayout or RelativeLayout to control the Z-axis ordering.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 1
    To get a square preview do the following: Create your own activity and inflate the CameraFragment and add it to the activity as shown in this example http://toastdroid.com/2014/03/14/cwac-camera-an-easier-way-to-take-photos-in-android/ . Replace the FrameLayout that R.id.container refers to with a custom square FrameLayout which you implement like thus http://stackoverflow.com/a/10157573/1666063 - now you've got a square preview. – Espen Riskedal Aug 13 '14 at 21:13
  • Yes, to get a square, must use other layout to cover up the unwanted area as @espen-riskedal said. Also notice that, preview size must have exact ratio as one of those from the parameters list. Otherwise, your preview will be stretched . Picture size must have exact ratio you picked in preview size. Otherwise, you output picture might look different than your preview screen. – John Pang Dec 12 '14 at 08:17