Parth Bhayani
Parth Bhayani

Reputation: 1924

How to set background to the outer portion of frame in android using surfaceview

enter image description here

Hello guys,

My problem is how can I fill the outer portion of the frame. I need to show the camera moments inside the frame only. The rest of the portion will filled up with the color what we choose to fill.

Here this is the whole background captured from the camera but I don't want this.

Please suggest me what I should do?

Your true guidance and support will be additional and your efforts will highly be appreciated once you're sure to done with this.

Upvotes: 0

Views: 247

Answers (1)

fadden
fadden

Reputation: 52313

You have two options if you don't want the camera preview to fill the entire area covered by the SurfaceView:

  1. Draw something on top of the SurfaceView.
  2. Use OpenGL ES to render the camera preview in whatever shape you want.

Option #1 is pretty straightforward. The SurfaceView surface is composited below the View UI layer, so anything you draw in a View will appear on top (e.g. the blue circle in the image you included). Just draw opaque pixels everywhere you don't want the camera preview to appear. You should be able to use the SurfaceView's View by specifying a custom onDraw().

Option #2 is more involved, but does give you more flexibility in how you display the camera image. The "texture from camera" activity in Grafika demonstrates this.

Upvotes: 1

Related Questions