Advertisement
Guest User

Untitled

a guest
Feb 6th, 2014
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. View u = findViewById(R.id.scroll);
  2. u.setDrawingCacheEnabled(true);
  3. ScrollView z = (ScrollView) findViewById(R.id.scroll);
  4. int totalHeight = z.getChildAt(0).getHeight();
  5. int totalWidth = z.getChildAt(0).getWidth();
  6. u.layout(0, 0, totalWidth, totalHeight);
  7. u.buildDrawingCache(true);
  8. Bitmap b = Bitmap.createBitmap(u.getDrawingCache());
  9. u.setDrawingCacheEnabled(false);
  10.  
  11. //Save bitmap
  12. String extr = Environment.getExternalStorageDirectory().toString() + File.separator + "Folder";
  13. String fileName = new SimpleDateFormat("yyyyMMddhhmm'_report.jpg'").format(new Date());
  14. File myPath = new File(extr, fileName);
  15. FileOutputStream fos = null;
  16. try {
  17. fos = new FileOutputStream(myPath);
  18. b.compress(Bitmap.CompressFormat.JPEG, 100, fos);
  19. fos.flush();
  20. fos.close();
  21. MediaStore.Images.Media.insertImage(getContentResolver(), b, "Screen", "screen");
  22. }catch (FileNotFoundException e) {
  23. // TODO Auto-generated catch block
  24. e.printStackTrace();
  25. } catch (Exception e) {
  26. // TODO Auto-generated catch block
  27. e.printStackTrace();
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement