有什么办法来听时,相机加载了? CWAC相机 [英] Is there any way to listen for when the camera has loaded in? cwac-camera

查看:247
本文介绍了有什么办法来听时,相机加载了? CWAC相机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的相机CWAC片段设置和一切工作很好。有一些自定义我想要做的。

I've got my CWAC Camera fragment setup, and everything is working nicely. There's a few customizations I'd like to do.


  1. 我想显示进度的相机片段加载到它的主机活动/片段

  2. 用户已拍摄的照片后,我想显示进度的拍照按钮再次叠加,让他们明白,他们不能立即拍照,直到相机准备再次

从寻找到了CWAC相机的文档,我还没有发现任何支持这种回调。这算哪门子的监听,甚至可能的事情?如果是这样,图书馆有一个简单的方法来做到这一点,我不是看?

From looking into the documentation for CWAC Camera, I haven't found anything that supports this sort of callback. Is this sort of thing even possible to listen for? If so, does the library have an easy way to do it that I'm not seeing?

在此先感谢您的帮助。

推荐答案

当相机装载和preVIEW开始,使用code要通知:

To be notified when the camera is loaded and preview started, use this code:

public class MyCameraFragment extends CameraFragment {

    CameraView cameraView;

    Camera.PreviewCallback previewCallback = new Camera.PreviewCallback() {
        @Override
        public void onPreviewFrame(byte[] data, Camera camera) {
            // camera is "loaded" and first preview is sent to the screen
            // do whatever you want to do
        }
    };

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        cameraView = // code to find your CameraView
    }

    @Override
    public void onResume() {
        super.onResume();
        Camera camera = cameraView.getCamera();
        if (null != camera) {
            camera.setOneShotPreviewCallback(previewCallback);
        }
    }

    private void somehowRestartedCameraViewForWhateverReason() {
        if (null != cameraView) {
            cameraView.onResume(); // force it to restart
            Camera camera = cameraView.getCamera();
            if (null != camera) {
                camera.setOneShotPreviewCallback(previewCallback);
            }
        }
    }
}

我用这个code更新UI,使闪光灯按钮只支持拍照时出现:

I used this code to update the UI, so that flash button only appears when camera supported:

camera.getParameters().getSupportedFlashModes()

返回非空目录和大小> 0,通常的前置摄像头没有闪光灯,但谁知道?

return non-null List and size > 0. Usually Front Facing Camera has no flash but who knows?

如果要切换摄像头,也请看到我的其他的答案在这里:
<一href=\"http://stackoverflow.com/questions/23329421/cwac-camera-multiple-camera-views-in-one-layout-and-switching-between-them/26694653#26694653\">CWAC相机 - 在一个布局多个摄像机视图(和它们之间切换)

If you want to switch camera, please also see my other answer here: CWAC Camera - Multiple camera views in one layout (and switching between them)

这篇关于有什么办法来听时,相机加载了? CWAC相机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆