Questions tagged [surfaceview]

SurfaceView is a widget on the Android platform which provides a dedicated drawing surface.

Android's SurfaceView class provides a dedicated drawing surface embedded inside of a View hierarchy. You can control the format of this surface and, if you like, its size; the SurfaceView takes care of placing the surface at the correct location on the screen.

A SurfaceView has two parts: the Surface, and the View. The Surface is a separate layer, independent of the View UI layer; by default it is positioned behind the View layer. The View works like any other View element, and is usually completely transparent, serving only to interact with other View elements during layout. In some situations it can be useful to draw on the View (e.g. for a static mask).

Because the Surface is an independent layer, it can be updated outside of the usual invalidate/refresh View cycle, on a dedicated thread.

Allocation of a display Surface is performed by the Window Manager. This requires an IPC round-trip, so the availability of and changes to Surfaces are reported through callbacks. This also makes it difficult to move a SurfaceView around smoothly, as the position of the View and position of the Surface may not update on the same frame.

Other View elements can be positioned to overlap the SurfaceView, including interactive elements like buttons. The Surface's Z-order can be altered to place it on top of the View layer. It isn't possible to sandwich the Surface between View elements; if you need that, consider TextureView instead.

The transparent region that makes the surface visible is based on the layout positions in the view hierarchy. If the post-layout transform properties are used to draw a sibling view on top of the SurfaceView, the view may not be properly composited with the surface.

For many applications, a custom view is a better choice.

Detailed information about SurfaceView can be found in the system-level graphics architecture document.

2733 questions
37
votes
6 answers

How to capture image from custom CameraView in Android?

i need to capture image from required portion of the screen. capture image from camera. at that time other screen content as it is. how is this possible?
Mr.Sandy
  • 4,299
  • 3
  • 31
  • 54
34
votes
8 answers

SurfaceView flashes black on load

I have a drawing app that takes about 2-5 seconds to load the drawing for complicated drawings (done via an AsyncTask). For a better user experience, during this time I flash the stored PNG version of the drawing I have from the app directory as an…
Unpossible
  • 10,607
  • 22
  • 75
  • 113
32
votes
5 answers

Overlay images onto Camera preview SurfaceView

I have a SurfaceView that is being used to draw images, and I would like to overlay them onto a live-feed from the phone's camera. Currently, the SurfaceView that contains the images have a white-background, but if I were to overlay them onto the…
GobiasKoffi
  • 4,014
  • 14
  • 59
  • 66
30
votes
1 answer

Minimize Android GLSurfaceView lag

Following some other questions on Stack Overflow, I've read the guide to the internals of Android Surfaces, SurfaceViews, etc from here: https://source.android.com/devices/graphics/architecture.html That guide has given me a much improved…
tangobravo
  • 898
  • 10
  • 24
29
votes
5 answers

Take a screenshot using MediaProjection

With the MediaProjection APIs available in Android L it's possible to capture the contents of the main screen (the default display) into a Surface object, which your app can then send across the network I have managed to get the VirtualDisplay…
Alessandro Roaro
  • 4,665
  • 6
  • 29
  • 48
29
votes
2 answers

BUG: createWindowSurface failed EGL_BAD_ALLOC

I have an application on Google Play for counting down numbers and letters. In this application I have the following activities: google sigin archivements admob service I use Google Analytics, and ACRA for error reporting. I don't use…
cayrodev
  • 373
  • 1
  • 4
  • 8
27
votes
4 answers

Color banding and artifacts with gradients despite using RGBA_8888 everywhere

I'm aware that colour banding is an old chestnut of a problem that has been discussed many times before with various solutions provided (which essentially boil down to use 32-bit throughout, or use dithering). In fact not so long ago I asked and…
Trevor
  • 10,903
  • 5
  • 61
  • 84
26
votes
7 answers

Android Camera will not work. startPreview fails

I'm getting these errors from LogCat: 10-30 00:31:51.494: D/CameraHal(1205): CameraHal setOverlay/1/00000000/00000000 10-30 00:31:51.494: E/CameraHal(1205): Trying to set overlay, but overlay is null!, line:3472 10-30 00:31:51.494:…
Matthew Mitchell
  • 5,293
  • 14
  • 70
  • 122
26
votes
4 answers

Android:How to add a button in surface view

I'm drawing some graphics and i would like to add a couple of buttons to it. But with the surface view how do we add these buttons programatically ?
m4n07
  • 2,267
  • 12
  • 50
  • 65
25
votes
1 answer

Fitting a camera preview to a SurfaceView larger than the display

I have an Android application that needs to fullscreen a camera preview regardless of the preview size given by getSupportedPreviewSizes() without distortion. I expect this to crop the preview by some amount in either the height or width, but this…
Daniel Smith
  • 8,561
  • 3
  • 35
  • 58
23
votes
1 answer

Zooming and drag feature in SurfaceView

I'm trying to create a SurfaceView that can be zoomed and dragged. It implements an HTTP image stream that draws directly into the canvas I've tried the following code and it kinda work... but it gives me problems in the borders. No idea of the…
Filnik
  • 352
  • 1
  • 12
  • 33
22
votes
6 answers

Take Screenshot of SurfaceView

Am developing a simple camera app. I have code that takes screenshot of the whole activity and writes it to the SD card. The problem is that the SurfaceView returns a black screen. I would like to know how to independently take a screenshot of the…
Donnie Ibiyemi
  • 971
  • 3
  • 15
  • 26
22
votes
6 answers

Override onDraw() or draw()?

My project is based on surfaceView and up until now I've had all of my rendering in onDraw which I am overriding. All seemed to be OK. However, I've just updated my SDK and now it gives me an error telling me: Suspicious method call; should…
Zippy
  • 3,826
  • 5
  • 43
  • 96
20
votes
0 answers

View gets cropped above 10.000 pixel width

UPDATE: Works on Emulator with Android Oreo (8.X). I have the possibility to do changes right to the android sources, so it would also help if someone knews what in the android sources I have to change or update to get this working (so I don't…
20
votes
1 answer

How do I use Android’s “Surface” classes?

Is there a detailed explanation of Surface, SurfaceHolder, EGLSurface, SurfaceView, GLSurfaceView, SurfaceTexture, and TextureView?  In particular: What’s the difference between SurfaceView and TextureView? Do I need to use GLSurfaceView to use…
fadden
  • 51,356
  • 5
  • 116
  • 166