本文介绍了mCamera.set$p$pview{@override在previewFrame()}不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  • 我要的录制视频并分析当前位图的服务。

  • 于是我在 onStartCommand 功能寄存器 surfaceHolder.addCallback

  • ,并设置 mCamera.set previewCallback surfaceCreated 功能。

  • 当我启动服务,似乎上previewFrame 函数不工作。

我不知道为什么,任何人都可以给我一个忙吗?

下面是服务 onStartCommand 函数的我的code。

  @覆盖
    公众诠释onStartCommand(意向意图,诠释标志诠释startId){
    如果(Util.checkCameraHardware(本)){
        mCamera = Util.getCameraInstance();
        如果(mCamera!= NULL){
            SurfaceView SV =新SurfaceView(本);            窗口管理WM =(窗口管理器)getSystemService(Context.WINDOW_SERVICE);
            WindowManager.LayoutParams PARAMS =新WindowManager.LayoutParams(1,1,
                    WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
                    WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
                    PixelFormat.TRANSLUCENT);
            SurfaceHolder SH = sv.getHolder();            sv.setZOrderOnTop(真);
            sh.setFormat(PixelFormat.TRANSPARENT);
            sh.addCallback(新SurfaceHolder.Callback(){
                @覆盖
                公共无效surfaceCreated(SurfaceHolder持有人){
                    Camera.Parameters PARAMS = mCamera.getParameters();
                    mCamera.setParameters(PARAMS);
                    Camera.Parameters p值= mCamera.getParameters();                    清单< Camera.Size> LISTSIZE;                    LISTSIZE = p.getSupported previewSizes();
                    Camera.Size米previewSize = listSize.get(2);
                    Log.v(TAG,preVIEW宽度=+ M previewSize.width
                            +preVIEW高度=+ M previewSize.height);
                    P.SET previewSize(M previewSize.width,男previewSize.height);                    LISTSIZE = p.getSupportedPictureSizes();
                    Camera.Size mPictureSize = listSize.get(2);
                    Log.v(TAG,捕获宽度=+ mPictureSize.width
                            +捕获高度=+ mPictureSize.height);
                    p.setPictureSize(mPictureSize.width,mPictureSize.height);
                    mCamera.setParameters(P);
                    尝试{
                        mCamera.set previewDisplay(支架);    / ******************* ************ /
                        mCamera.set previewCallback(新相机。previewCallback(){
                            @覆盖
                            在previewFrame(字节[]数据,相机摄像头){公共无效
                                如果(_calibrationsLeft == -1)
                                    返回;                                如果(_calibrationsLeft大于0){
                                    //做校准!                                    如果(_currentFaceDetectionThread!= NULL
                                            &功放;&安培; _currentFaceDetectionThread.isAlive()){
                                        //删除帧
                                        返回;
                                    }                                    //没有人脸检测启动或已完成
                                    _processTimeForLastFrame = System.currentTimeMillis的()
                                             - _lastFrameStart;
                                    _lastFrameStart = System.currentTimeMillis的();                                    如果(_currentFaceDetectionThread!= NULL){
                                        _calibrationsLeft--;
                                        updateMeasurement(_currentFaceDetectionThread.getCurrentFace());                                        如果(_calibrationsLeft == 0){
                                            doneCalibrating();
                                            返回;
                                        }
                                    }                                    _currentFaceDetectionThread =新FaceDetectionThread(数据,
                                            _ previewSize);
                                    _currentFaceDetectionThread.start();                                }其他{
                                    //简单的测量                                    如果(_currentFaceDetectionThread!= NULL
                                            &功放;&安培; _currentFaceDetectionThread.isAlive()){
                                        //删除帧
                                        返回;
                                    }                                    //没有人脸检测启动或已完成
                                    _processTimeForLastFrame = System.currentTimeMillis的()
                                             - _lastFrameStart;
                                    _lastFrameStart = System.currentTimeMillis的();                                    如果(_currentFaceDetectionThread!= NULL)
                                        updateMeasurement(_currentFaceDetectionThread.getCurrentFace());                                    _currentFaceDetectionThread =新FaceDetectionThread(数据,
                                            _ previewSize);
                                    _currentFaceDetectionThread.start();
                                }
                            }
                        });
     / ******************* *************************** /
                    }赶上(IOException异常五){
                        e.printStackTrace();
                    }
                    mCamera.start preVIEW();
                    。MessageHUB.get()的sendMessage(MessageHUB.LOG_ preVIEW,NULL);
                    mCamera.unlock();
                    校准();
                }                @覆盖
                公共无效surfaceChanged(SurfaceHolder架,INT格式,诠释的宽度,高度INT){
                }                @覆盖
                公共无效surfaceDestroyed(SurfaceHolder持有人){
                }
            });
            wm.addView(SV,则params);        }其他{
            Log.d(TAG,====从服务中获得相机失败);        }
    }其他{
        Log.d(TAG,====有设备上没有摄像头的硬件。);
    }    返回super.onStartCommand(意向,旗帜,startId);
}


解决方案

您似乎停止surfacechanged

里面的摄像头preVIEW

  mCamera.stop preVIEW();

请尝试重新启动内部onSurfaceChanged preVIEW

这篇关于mCamera.set$p$pview{@override在previewFrame()}不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 06:32