TextureView
원문이 짧기 때문에 여기에 전부 적어둔다.
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.
요약하면 동영상이나 그래픽(OpenGL)을 보여주기 위한 뷰라는 뜻.
TextureView can only be used in a hardware accelerated window. When rendered in software, TextureView will draw nothing.
꽤 무거운 그래픽 처리를 해야되기 때문에 하드웨어 가속 윈도우에서만 사용 가능하다. (소프트웨어에서 렌더링을 시도하면 일을 안한다고 함.)
Unlike SurfaceView, TextureView does not create a separate window but behaves as a regular View. This key difference allows a TextureView to be moved, transformed, animated, etc. For instance, you can make a TextureView semi-translucent by calling myView.setAlpha(0.5f).
SurfaceView(이하 SV)와 달리, 별도의 창을 만들지는 않고 일반적인 뷰처럼 행동한다. 이 점 때문에 TextureView(이하 TV)는 이동, 변환, 애니메이션 등등이 자유롭게 이루어진다.
예로 myView.setAlpha(0.5f) 같은 코드로 반투명으로 만들 수 있다.
Using a TextureView is simple: all you need to do is get its SurfaceTexture. The SurfaceTexture can then be used to render content. The following example demonstrates how to render the camera preview into a TextureView:
TextureView는 간단하게 사용가능함: TV의 SurfaceTexture만 가져오면 된다. SurfaceTexture를 이용해서 콘텐츠를 렌더링한다.
아래 예시는 카메라 미리보기를 TV를 이용해서 렌더링하는 예제를 보여준다.
(주의 : 구 버전 Camera API(android.hardware.Camera) 라서 취소선이 그어지거나 심지어 작동하지 않을 수도 있음 )
public class LiveCameraActivity extends Activity implements TextureView.SurfaceTextureListener { private Camera mCamera; private TextureView mTextureView; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mTextureView = new TextureView(this); mTextureView.setSurfaceTextureListener(this); setContentView(mTextureView); } public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { mCamera = Camera.open(); try { mCamera.setPreviewTexture(surface); mCamera.startPreview(); } catch (IOException ioe) { // Something bad happened } } public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { // Ignored, Camera does all the work for us } public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { mCamera.stopPreview(); mCamera.release(); return true; } public void onSurfaceTextureUpdated(SurfaceTexture surface) { // Invoked every time there's a new Camera preview frame } }
A TextureView's SurfaceTexture can be obtained either by invoking getSurfaceTexture() or by using a 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.
TV의 SurfaceTexture는 getSurfaceTexture() 나 SurfaceTextureListener를 통해서 얻을 수 있다.
SurfaceTexture는 TV가 창에 붙여지고 난 다음부터 사용가능하다. (즉, onAttachedToWindow() 가 호출되고 난 다음부터)
SurfaceTexture가 사용가능할 때를 알기 위한 리스너를 사용하는 것이 강력하게 추천된다.
It is important to note that only one producer can use the TextureView. For instance, if you use a TextureView o display the camera preview, you cannot use lockCanvas() to draw onto the TextureView at the same time.
단 하나의 프로듀서(producer)만 TV를 사용가능하다는 점이 중요하다.
예를 들어서, TV를 사용해서 카메라 미리보기를 보여줄 때, 그 동시에 lockCanvas() 를 TV 위에다가 그리기 위해서 사용하는 것은 불가능 하다.