Advertisement
amjadArabia

ScreenShot

Jan 22nd, 2018
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. MainActivity
  2. public class MainActivity extends AppCompatActivity {
  3.  
  4.  
  5.     private View main;
  6.     private ImageView imageView;
  7.     Button btn;
  8.  
  9.  
  10.     @Override
  11.     protected void onCreate(Bundle savedInstanceState) {
  12.         super.onCreate(savedInstanceState);
  13.         setContentView(R.layout.activity_main);
  14.  
  15.         main = findViewById(R.id.main);
  16.         imageView = findViewById(R.id.imageView);
  17.         btn = findViewById(R.id.btn);
  18.  
  19.  
  20.  
  21.         btn.setOnClickListener(new View.OnClickListener() {
  22.             @Override
  23.             public void onClick(View v) {
  24.                 Bitmap b = ScreenShot.takescreenshotOfRootView(imageView);
  25.                 imageView.setImageBitmap(b);
  26.                 main.setBackgroundColor(Color.parseColor("#999999"));
  27.  
  28.             }
  29.         });
  30.     }
  31. }
  32.  
  33.  
  34. ScreenShot.java
  35. ======================
  36.  
  37. public class ScreenShot {
  38.  
  39.     public static Bitmap takescreenshot(View v){
  40.         v.setDrawingCacheEnabled(true);
  41.         v.buildDrawingCache();
  42.  
  43.         Bitmap b = Bitmap.createBitmap(v.getDrawingCache());
  44.         v.setDrawingCacheEnabled(false);
  45.         return b;
  46.  
  47.     }
  48.  
  49.     public static Bitmap takescreenshotOfRootView(View v )
  50.     {
  51.         return takescreenshot(v.getRootView());
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement