简体   繁体   English

CWAC相机的预览尺寸

[英]Preview size wtith CWAC-Camera

I've been fighting for a while with https://github.com/commonsguy/cwac-camera 我已经和https://github.com/commonsguy/cwac-camera战斗了一段时间

Managed to create my custom CameraFragment and a custom custom CameraHost . 设法创建我的自定义CameraFragment和自定义自定义CameraHost

I've overrode getPictureSize and getPreviewSize . 我已经覆盖了getPictureSizegetPreviewSize With those two methods I'm able to find out which Size s are able to be used. 有了这两种方法我能找出哪些Size s为能够使用。 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. 我一直在测试,没有设备返回方形格式的Size ,所以我猜最好的方法是将Size设置为最接近我的需求。 Like if I need an 800x800 squared image, I will return the nearest Size , that would be (for example) 1280x1024 就像我需要800x800平方的图像一样,我将返回最近的Size ,即(例如)1280x1024

So far so good. 到现在为止还挺好。 The issue is the following: 问题如下:

Documentation states: 文档状态:

Usually, your CameraHost will be called with getPreviewSize() 通常,您的CameraHost将使用getPreviewSize()进行调用

Damn; 该死的; my Nexus5 device never triggers this method, but a Genymotion emulator does. 我的Nexus5设备从不触发此方法,但Genymotion模拟器会触发。 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? 在第二个学期,我需要一些小技巧:如果我想要一个平方预览大小,我知道这将无法使用默认Size S按返回getSupportedPreviewSizes ,我能做些什么来显示一个平方? Maybe overlaying a square on top of CameraFragment ? 也许在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. 作为Android开发人员,这很棒。

Thank you. 谢谢。

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() . 如果getRecordingHint()返回ANYVIDEO_ONLY ,则CameraHost通过getPreferredPreviewSizeForVideo()而不是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. 如果您希望对视频使用不同的预览大小,请返回它,否则返回null ,我们将改用getPreviewSize()的结果。

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. 在API级别11+上, SimpleCameraHost getPreferredPreviewSizeForVideo()的实现委派到Camera.Parameters上的getPreferredPreviewSizeForVideo()实现,但已知会为其返回差值的设备除外。

what can I do to display an square? 如何显示正方形? Maybe overlaying a square on top of CameraFragment? 也许在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. 我会尝试将CameraView直接放置在您自己的UI中,然后使用FrameLayoutRelativeLayout来控制Z轴顺序,然后在其上分层。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM