Skip to content

Instantly share code, notes, and snippets.

@asanand3
Created August 11, 2015 09:30
Show Gist options
  • Save asanand3/d66c7629a1701ee4fc87 to your computer and use it in GitHub Desktop.
Save asanand3/d66c7629a1701ee4fc87 to your computer and use it in GitHub Desktop.
try{
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.bubble_green);
//replace "R.drawable.bubble_green" with the image resource you want to share from drawable
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
largeIcon.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
// you can create a new file name "test.jpg" in sdcard folder.
File f = new File(Environment.getExternalStorageDirectory() + File.separator + "test.jpg");
f.createNewFile();
// write the bytes in file
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
// remember close de FileOutput
fo.close();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment