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 ?

opc0de
  • 11,557
  • 14
  • 94
  • 187

1 Answers1

0

Its hard to tell without logs but my guess is that lockCanvas() returns null. This happens when you call lockCanvas when the Surface is not available. Check surfaceCreated and surfaceDestroyed. Another, but maybe unrelated issue with your code are the coordinates you use with drawText(). (0,0) means that the text is drawn outside the visible area.

Renard
  • 6,909
  • 2
  • 27
  • 23