Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. java.io.FileNotFoundException: /storage/emulated/0/SAVE IMAGE EXAMPLE/myimage.png (No such file or directory)
  2.  
  3. final PieChart piechart = (PieChart) findViewById(R.id.piechart);
  4.  
  5.  
  6. button2.setOnClickListener(new View.OnClickListener() {
  7. public void onClick (View v) {
  8. Toast.makeText(Main.this, "Chart Saved", Toast.LENGTH_SHORT).show();
  9. piechart.setCenterText("Test");
  10. Bitmap bitmap;
  11. OutputStream output;
  12.  
  13. bitmap = BitmapFactory.decodeResource(getResources(),R.id.piechart);
  14.  
  15. File filepath = Environment.getExternalStorageDirectory();
  16.  
  17. File dir = new File(filepath.getAbsolutePath()+"/SAVE IMAGE EXAMPLE");
  18. dir.mkdirs();
  19.  
  20. File file = new File(dir, "myimage.png");
  21.  
  22. try {
  23. output = new FileOutputStream(file);
  24.  
  25. bitmap.compress(Bitmap.CompressFormat.PNG, 100, output);
  26. output.flush();
  27. output.close();
  28.  
  29.  
  30. }catch(Exception e){
  31. e.printStackTrace();
  32. }
  33.  
  34. }
  35. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement