0

I am doing an application witch uses the webcam and i want to display some text after the picture is taken so in the method ShutterCallBack i wrote this

    ShutterCallback shutterCallback = new ShutterCallback() {
        public void onShutter() {
            Log.d("DHA", "onShutter'd");
            Canvas cnv = mSurfaceHolder.lockCanvas(null);
            Log.w("DHA", "Nana");
            Paint p = new Paint();
            Log.w("DHA", "Nana2");
            p.setColor(Color.RED);
            Log.w("DHA", "Nana3");
            cnv.drawText("Hello", 0, 0, p);
            Log.w("DHA", "Nana4");
            mSurfaceHolder.unlockCanvasAndPost(cnv);
            Log.w("DHA", "Nana5");
        }
    };

It fails awfuly terminating my application...How can i write text on the surface ?

4

1 回答 1

0

没有日志很难判断,但我的猜测是lockCanvas()返回 null。当 Surface 不可用时调用 lockCanvas 会发生这种情况。检查surfaceCreated 和surfaceDestroyed。另一个与您的代码可能无关的问题是您与 drawText() 一起使用的坐标。(0,0) 表示文本绘制在可见区域之外。

于 2012-04-24T11:41:45.190 回答