3

我的相机应用程序在显示之前使用 OpenCV 处理帧。尽管相机预览有效,但 logcat 仍会出现以下错误:

E/BufferQueue(22797): [unnamed-22797-0] dequeueBuffer: SurfaceTexture 已被废弃!E/SecCameraHardware(2078): 无法使 gralloc 缓冲区出列!05-03 13:29:12.716 E/ISecCameraHardware(2078): bool android::ISecCameraHardware::previewThread()::flushSurface() 失败

以下是相关代码,改编自 OpenCV 的示例代码:

mCamera.setPreviewCallbackWithBuffer(new PreviewCallback() {
    public void onPreviewFrame(byte[] data, Camera camera) {
        synchronized (CameraView.this) {
            System.arraycopy(data, 0, mFrame, 0, data.length);
            CameraView.this.notify();
        }
        camera.addCallbackBuffer(mBuffer);
    }
});

[...]

mBitmap = Bitmap.createBitmap(mFrameWidth, mFrameHeight, 
    Bitmap.Config.ARGB_8888); 

try {
    mCamera.setPreviewTexture(new SurfaceTexture(10));
} catch (IOException e) {};

mCamera.startPreview();

[...]

public void run() {
    mThreadRun = true;
    Log.i(TAG, "Starting processing thread");
    while (mThreadRun) {
        synchronized (this) {
            try {
                this.wait();
                processFrame(mFrame);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        Canvas canvas = mHolder.lockCanvas();
        if (canvas != null) {
            canvas.drawBitmap(mBitmap,
                    (canvas.getWidth() - mFrameWidth) / 2,
                    (canvas.getHeight() - mFrameHeight) / 2, null);
            mHolder.unlockCanvasAndPost(canvas);
        }
    }
}

我注意到一个与此错误相关的现有问题,但建议的解决方案 - 在设置预览纹理之前创建位图以进行显示 - 对我没有影响。

4

0 回答 0