0

我正在开发一个需要在 previewcallback() 函数中处理预览的每一帧的android应用程序,我的代码是这样的:

Camera c = null;

        try {
            c = Camera.open(1); // attempt to get a Camera instance

        }
        catch (Exception e){
            // Camera is not available (in use or does not exist)
        }
        Camera.Size csize = c.getParameters().getPreviewSize();
        int mPreviewHeight = csize.height; //
        int mPreviewWidth = csize.width;
        Camera.Parameters parameters = c.getParameters();
        parameters.setPictureSize(800, 800);
       // parameters.setPreviewSize(700, 700);
        parameters.set("orientation", "portrait");
        c.setDisplayOrientation(90);
        c.setParameters(parameters);
        mPreview = new CameraPreview(this, c);
        FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);

        preview.addView(mPreview);
        final PreviewCallback mPicture = new PreviewCallback() {

            public void onPreviewFrame(byte[] data, Camera camera)  
            { 
                    try 
                    { 
                            BitmapFactory.Options opts = new BitmapFactory.Options(); 
                            Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);//,opts); 
                            Log.i("file","Bitmap captured");
                    } 
                    catch(Exception e) 
                    {

                    } 
            } 

        };

        c.setPreviewCallback(mPicture);

但看起来日志“位图捕获”从未显示,这意味着 previewcallback 功能无法正常运行,有人可以帮我解决这个问题吗?先感谢您!

4

1 回答 1

0

您的 CameraPreview 课程中有什么?

我猜你在哪里打电话c.startPreview()

于 2012-11-19T03:31:32.927 回答