Skip to content

Instantly share code, notes, and snippets.

@DavidTPate
Created February 13, 2013 04:47
Show Gist options
  • Save DavidTPate/4942363 to your computer and use it in GitHub Desktop.
Save DavidTPate/4942363 to your computer and use it in GitHub Desktop.
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
// If your preview can change or rotate, take care of those events here.
// Make sure to stop the preview before resizing or reformatting it.
if (mHolder.getSurface() == null) {
// preview surface does not exist
Log.d(TAG, "Preview Surface does not exist");
return;
}
// stop preview before making changes
try {
mCamera.stopPreview();
Log.d(TAG, "Camera Stopped Successfully");
} catch (Exception e) {
Log.d(TAG, "Error Stopping Camera, it most likely is a non-existent preview");
}
// set preview size and make any resize, rotate or
// reformatting changes here
// start preview with new settings
try {
mCamera.setPreviewDisplay(mHolder);
mCamera.startPreview();
Log.d(TAG, "Preview Started Successfully");
} catch (Exception e) {
Log.d(TAG, "Error starting camera preview: " + e.getMessage());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment