Paul S
Paul S

Reputation: 279

How to clear preview frame from surface after stopPreview

When I call stopPreview on my camera, the last frame remains on the surfaceview. How do I clear it, to black for example?

I tried setBackGroundColor, setVisibility but neither make a difference. I assume because it is of type PUSH_BUFFER.

Thanks

Upvotes: 4

Views: 2464

Answers (2)

Paul S
Paul S

Reputation: 279

Thanks Lior,

Unfortunately, I made a schoolboy error and assumed 0 was black when using setBackGroundColor.

Having actually read the docs this is transparent so am now using Color.BLACK which works as expected.

Upvotes: 0

Lior Ohana
Lior Ohana

Reputation: 3527

Did you try the following? On your surface view, override the onDraw with something like this:

@Override
public void draw(Canvas canvas) {
   super.draw(canvas);

   if (m_stopped) // Set it to true when you stop the preview.
   {
       canvas.drawColor(Color.BLACK);
   }
}

You might need to call invalidate() after you stop the preview in order to make sure the onDraw is called.

Upvotes: 2

Related Questions