카테고리 없음2014. 11. 14. 11:54













SurfaceView와 그 부속 함수 사용 정리가 필요하다.

이것 저것 테스트한 코드를 쌓았다.

public class MySurfaceVwActy extends Activity { private static final String TAG = MySurfaceVwActy.class.getSimpleName(); SurfaceView surfaceView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // requestWindowFeature(Window.FEATURE_NO_TITLE); //setContentView 앞|뒤에 오면? 에러!! // setContentView(R.layout.activity_my_surface_view); Log.d(TAG, "*********************************************************"); Log.d(TAG, "*********************************************************"); TestView surfaceEvent = new TestView(getApplicationContext()); // TestView surfaceEvent = new TestView(MyTestViewActy.this); // surfaceEvent.setZOrderOnTop(true);     // surfaceEvent.getHolder().setFormat(PixelFormat.TRANSPARENT); // addContentView(surfaceEvent, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); setContentView(surfaceEvent); Button buttonStartCameraPreview = (Button)findViewById(R.id.startcamerapreview); Button buttonStopCameraPreview = (Button)findViewById(R.id.stopcamerapreview); Log.d(TAG, "onCreate() end"); } } class TestView extends SurfaceView implements SurfaceHolder.Callback { private static final String TAG_sfvw = MySurfaceVwActy.class.getSimpleName(); private SurfaceHolder mHolder; public TestView(Context context) { super(context); Log.d(TAG_sfvw, "Surface() "); mHolder = getHolder(); mHolder.addCallback(this); }

@Override public void surfaceCreated(SurfaceHolder holder) { Log.d(TAG_sfvw, "surfaceCreated() "); android.graphics.Canvas cnvs = null; try { cnvs = getHolder().lockCanvas(null); synchronized(getHolder()) { android.graphics.Paint pnt = new android.graphics.Paint(); pnt.setColor(android.graphics.Color.GREEN); cnvs.drawCircle(100, 100, 50, pnt); } } finally { if(cnvs != null) getHolder().unlockCanvasAndPost(cnvs); } } @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { Log.d(TAG_sfvw, "surfaceChanged() "); } @Override public void surfaceDestroyed(SurfaceHolder holder) { Log.d(TAG_sfvw, "surfaceDestroyed() "); } }






Posted by 코드버무려