Skip to content

Instantly share code, notes, and snippets.

@talenguyen
Created August 27, 2015 08:50
Show Gist options
  • Save talenguyen/5d27854fd9558795dd8e to your computer and use it in GitHub Desktop.
Save talenguyen/5d27854fd9558795dd8e to your computer and use it in GitHub Desktop.
Useful stub in Android Development
public void captureView(View view, File outputFile) {
//Create a Bitmap with the same dimensions
Bitmap image = Bitmap.createBitmap(
avatarSize,
avatarSize,
Bitmap.Config.RGB_565);
//Draw the view inside the Bitmap
view.draw(new Canvas(image));
//Store to sdcard
try {
if (outputFile.exists()) {
outputFile.delete();
}
FileOutputStream out = new FileOutputStream(outputFile);
image.compress(Bitmap.CompressFormat.PNG, 90, out); //Output
} catch (Exception e) {
e.printStackTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment