Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. package com.example.amirqadir.screenshot;
  2. import android.app.Activity;
  3. import android.graphics.Bitmap;
  4. import android.graphics.Point;
  5. import android.graphics.Rect;
  6. import android.view.View;
  7.  
  8. import java.io.FileOutputStream;
  9. import java.io.IOException;
  10. /**
  11. * Created by Amir Qadir on 8/21/2017.
  12. */
  13.  
  14. public class Utility {
  15.  
  16. public static Bitmap takeScreenshot(Activity activity)
  17. {
  18. View view = activity.getWindow().getDecorView();
  19. view.setDrawingCacheEnabled(true);
  20. view.buildDrawingCache();
  21.  
  22. Bitmap b1 = view.getDrawingCache();
  23. Rect frame = new Rect();
  24. activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
  25.  
  26. int statusBarheight = frame.top;
  27.  
  28. Point size = new Point();
  29. activity.getWindowManager().getDefaultDisplay().getSize(size);
  30. int width = size.x;
  31. int height = size.y;
  32.  
  33. Bitmap b = Bitmap.createBitmap(b1,0,statusBarheight,width,height-statusBarheight);
  34. view.destroyDrawingCache();
  35. return b;
  36. }
  37.  
  38. public static void savePic(Bitmap b,String strFilename)
  39. {
  40. FileOutputStream fos;
  41. try {
  42. fos = new FileOutputStream(strFilename);
  43. b.compress(Bitmap.CompressFormat.PNG,90,fos);
  44. fos.flush();
  45. fos.close();
  46. }catch(IOException e)
  47. {
  48. e.printStackTrace();
  49. }
  50. }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement