最終更新:2016-01-04 (月) 14:52:47 (3006d)
android.view.TextureView
Top / android.view.TextureView
Android/APIレベル14(Android 4.0)~
http://developer.android.com/reference/android/view/TextureView.html
概要
- A TextureView can be used to display a content stream.
- Such a content stream can for instance be a video or an OpenGL scene. The content stream can come from the application's process as well as a remote process.
- TextureView can only be used in a hardware accelerated window. When rendered in software, TextureView will draw nothing.
継承
使い方
android.graphics.SurfaceTexture
- Captures frames from an image stream as an OpenGL ES texture.
- Using a TextureView is simple: all you need to do is get its SurfaceTexture. The SurfaceTexture can then be used to render content.
- A TextureView's SurfaceTexture can be obtained either by invoking TextureView.getSurfaceTexture() or by using a TextureView.SurfaceTextureListener.
- It is important to know that a SurfaceTexture is available only after the TextureView is attached to a window (and onAttachedToWindow?() has been invoked.)
- It is therefore highly recommended you use a listener to be notified when the SurfaceTexture becomes available.
メモ
- Unlike SurfaceView, TextureView does not create a separate window but behaves as a regular View.
- It is important to note that only one producer can use the TextureView. For instance, if you use a TextureView to display the camera preview, you cannot use TextureView.lockCanvas() to draw onto the TextureView at the same time.
イベントリスナ
- TextureView.SurfaceTextureListener
onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) Invoked when a TextureView's SurfaceTexture is ready for use. onSurfaceTextureDestroyed?(SurfaceTexture surface) Invoked when the specified SurfaceTexture is about to be destroyed. onSurfaceTextureSizeChanged?(SurfaceTexture surface, int width, int height) Invoked when the SurfaceTexture's buffers size changed. onSurfaceTextureUpdated?(SurfaceTexture surface) Invoked when the specified SurfaceTexture is updated through SurfaceTexture.updateTexImage(). - It is therefore highly recommended you use a listener to be notified when the SurfaceTexture becomes available.
SurfaceViewとの違い
メモ
- TextureViewの中身はOpenGL ESで言うところのテクスチャレンダリング
- 内部的にBitmapを持っていてそこに描画
- アクティビディのライフサイクルにかかわらず保持
- 垂直同期を取らない
- 内部でBitmap(SurfaceTextureを持つ)
参考
- Android 勉強会 #2 TextureViewのご紹介
- http://dev.classmethod.jp/slide/introduction_textureview_20130116/