Created
August 27, 2015 08:50
-
-
Save talenguyen/5d27854fd9558795dd8e to your computer and use it in GitHub Desktop.
Useful stub in Android Development
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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