Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MainActivity
- public class MainActivity extends AppCompatActivity {
- private View main;
- private ImageView imageView;
- Button btn;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- main = findViewById(R.id.main);
- imageView = findViewById(R.id.imageView);
- btn = findViewById(R.id.btn);
- btn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Bitmap b = ScreenShot.takescreenshotOfRootView(imageView);
- imageView.setImageBitmap(b);
- main.setBackgroundColor(Color.parseColor("#999999"));
- }
- });
- }
- }
- ScreenShot.java
- ======================
- public class ScreenShot {
- public static Bitmap takescreenshot(View v){
- v.setDrawingCacheEnabled(true);
- v.buildDrawingCache();
- Bitmap b = Bitmap.createBitmap(v.getDrawingCache());
- v.setDrawingCacheEnabled(false);
- return b;
- }
- public static Bitmap takescreenshotOfRootView(View v )
- {
- return takescreenshot(v.getRootView());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement