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
9
votes
1 answer

Getting Bitmap from Custom SurfaceView

I have this code in a class that extends surface view and implements runnable I am able to use the class basically allows you to draw to the canvas using different colors and such. I'm trying to get a method that will allow me to save the image…
Lpc_dark
  • 2,834
  • 7
  • 32
  • 49
9
votes
2 answers

get "[SurfaceView] connect: already connected" error if I draw a bitmap as the background of SurfaceView and then play video

What I want to do is Show a background image on the SurfaceView before starting to play video. I tried to just draw a jpeg image as its background of SurfaceView. It worked. I also tried to play a video on the SurfaceView. It also worked.…
hamer
  • 123
  • 1
  • 6
9
votes
2 answers

null Canvas in SurfaceView Thread, despite stopping Thread in surfaceDestroyed() - only on Android 4 / ICS

I have a SurfaceView extension where the bare bones of it are implemented as in the Lunar Lander example. That is, the run() method of the drawing Thread is essentially: public void run() { while (mRun) { Canvas c; try { …
Trevor
  • 10,903
  • 5
  • 61
  • 84
9
votes
6 answers

SurfaceView in Layout

So I've done a lot of searching but still can't seem to find the exact reason as to why my SurfaceView won't display. Here's a little background as to what I'm doing: I have a Linear Layout that is set Horizontally. It contains an ImageView, then a…
akappel
  • 209
  • 1
  • 3
  • 15
8
votes
1 answer

How does android handle differences between preview size/ratio and actual SufaceView size?

I'm writing a small android app where a user can place an image inside the live preview of the camera and take a picture of this. The app will then combine the two images appropriately -- All of this is working fine. I understand you can get/set the…
Ivo van der Wijk
  • 16,341
  • 4
  • 43
  • 57
8
votes
1 answer

Scaling a Bitmap to fit in a canvas

Im trying to write a game on droid, the way i take care of different screen resolutions is i make a bitmap with a target resolution (320x480), make a canvas from it and draw all the elements on it using fixed coordinates, then i just draw this…
user924941
  • 943
  • 3
  • 12
  • 24
8
votes
2 answers

How to implement double tap for surface view in android

Please tell how to implement double tap for SurfaceView in Android using gesture detector. Can anybody provide code example?
mohan
  • 13,035
  • 29
  • 108
  • 178
8
votes
2 answers

Android Surfaceview Threads and memory leaks

Im creating a game in android, and i noticed that the game has a memory leak. Iv managed to isolate the memory leak into a smaller application so that i can see well try and work out, how to fix it. The application uses a surfaceview for its view…
Spider
  • 156
  • 2
  • 8
8
votes
1 answer

Show my Layout while SurfaceView is loading Camera Preview

I have a simple screen with a start button. When the Start button is pressed, I want to go to a new Screen with a SurfaceView to show the Camera in. Everything works fine, but the Camera takes a while to load, and this gives me a black screen. I…
Entreco
  • 12,738
  • 8
  • 75
  • 95
8
votes
0 answers

Android Bitmap to WebRtc I420 Frame corrupted

Trying to stream bitmaps over WebRtc. My Capturer class looks approximately like this: public class BitmapCapturer implements VideoCapturer, VideoSink { private Capturer capturer; private int width; private int height; private SurfaceTextureHelper…
8
votes
3 answers

Why is lockCanvas() slow?

I'm implementing a SurfaceView subclass, where I run a separate thread to draw onto a SurfaceHolders Canvas. I'm measuring time before and after call to lockCanvas(), and I'm getting from about 70ms to 100ms. Does anyone could point me why i'm…
kaneda
  • 5,981
  • 8
  • 48
  • 73
8
votes
4 answers

Set the Background Image of a SurfaceView

Is there a way to set the background image of a SurfaceView? Does it have to be done in xml or can I do it all in Java - I've got something that looks like this in my constructor: Drawable sky = (getResources().getDrawable(R.drawable.sky)); …
Hani Honey
  • 2,101
  • 11
  • 48
  • 76
8
votes
0 answers

Instagram-like photo browser and a camera feature in android

I am developing one application, I am trying to develop same like instagram photo / video capture tool. I found very nice tutorial sample in iOS : https://github.com/ytakzk/Fusuma Does anybody know something similar library for android as well?…
8
votes
2 answers

Android: Dynamically Blur Surface with Video

I am building an Android application where an ExoPlayer plays a video onto the surface of a SurfaceView, and I am investigating whether it is possible to dynamically blur the playing video. Blurring techniques that involve first generating a bitmap…
M.S.
  • 1,091
  • 1
  • 11
  • 27
8
votes
1 answer

How can I get bitmap from surfaceView?

I want to capture bitmap image from custom surfaceView. and I try to setBitmapImage in imageView. But, the surfaceView saves nothing. Here is my Android code: import android.content.Context; import android.graphics.Bitmap; import…
bubu uwu
  • 463
  • 2
  • 12
  • 26