Advertisement
FaizanAhmed123

Untitled

Mar 26th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. private String saveToInternalStorage(Bitmap bitmapImage){
  2. ContextWrapper cw = new ContextWrapper(getApplicationContext());
  3. // path to /data/data/yourapp/app_data/imageDir
  4. File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);
  5. // Create imageDir
  6. File mypath=new File(directory,"image.jpg");
  7.  
  8. FileOutputStream fos = null;
  9. try {
  10. fos = new FileOutputStream(mypath);
  11. // Use the compress method on the BitMap object to write image to the OutputStream
  12. bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, fos);
  13. } catch (Exception e) {
  14. e.printStackTrace();
  15. } finally {
  16. try {
  17. fos.close();
  18. } catch (IOException e) {
  19. e.printStackTrace();
  20. }
  21. }
  22. return directory.getAbsolutePath();
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement