How to exit SurfaceView?
I draw something on canvas using SurfaceView. How can I define a way to
cancelling the surfaceView once the user is done? Below is my SurfaceView
implementation. The DrawOnTop class has the onDraw() but I initialize all
the variables in Preview class.
public class Preview extends SurfaceView implements SurfaceHolder.Callback {
SurfaceHolder mHolder;
DrawOnTop mDrawOnTop;
boolean mFinished;
Preview(Context context, DrawOnTop drawOnTop) {
super(context);
mDrawOnTop = drawOnTop;
mFinished = false;
// Install a SurfaceHolder.Callback so we get notified when the
// underlying surface is created and destroyed.
mHolder = getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
public void surfaceCreated(SurfaceHolder holder) {
//I set the bitmaps etc here
mDrawOnTop.mBitmap = Bitmap.createBitmap(mDrawOnTop.mImageWidth,
mDrawOnTop.mImageHeight, Bitmap.Config.ARGB_8888);
mDrawOnTop.mBitmap.setPixels(mDrawOnTop.mRGBData, 0,
mDrawOnTop.mImageWidth, 0, 0, mDrawOnTop.mImageWidth,
mDrawOnTop.mImageHeight);
mDrawOnTop.invalidate();
}
public void surfaceDestroyed(SurfaceHolder holder) {
mFinished = true;
}
public void surfaceChanged(SurfaceHolder holder, int format, int w,
int h) {
}
}
No comments:
Post a Comment