Reputation: 5506
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 Size
s 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 Size
s 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.
Upvotes: 2
Views: 724
Reputation: 1006869
Why is it just "usually"? What can I do to change it to "always"?
Quoting the documentation:
If
getRecordingHint()
returnsANY
orVIDEO_ONLY
, though,CameraHost
supplies the preview size viagetPreferredPreviewSizeForVideo()
instead ofgetPreviewSize()
. If you wish to use a different preview size for video, return it, otherwise returnnull
and we will use the results fromgetPreviewSize()
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.
Upvotes: 3