Reputation: 37
I'm trying to apply this code to get a screenshot of a view without an actionbar:
View main = findViewById(R.id.view);
Bitmap screenshot;
main.setDrawingCacheEnabled(true);
screenshot = Bitmap.createBitmap(main.getDrawingCache());
main.setDrawingCacheEnabled(false);
My question is how i can get the view if we don't have a layout,the view is set like:
setContentView(new MyView(this));
please take a look at this project: https://github.com/valerio-bozzolan/AcrylicPaint/blob/master/src/anupam/acrylic/EasyPaint.java Any help would be very appreciated!
UPDATE:
I got java.lang.NullPointerException at this line:
View v = new MyView(getBaseContext());
v.setDrawingCacheEnabled(true);
Bitmap cachedBitmap = v.getDrawingCache();
Bitmap copyBitmap = cachedBitmap.copy(Bitmap.Config.RGB_565, true); // <--- HERE
Happy new year!
Upvotes: 0
Views: 478
Reputation: 23972
If you're assigning the View
programmatically, then you already have it:
View view = new MyView(context);
setContentView(view);
Now you can draw contents of view
into Bitmap
and save it wherever you want (search for solutions, I don't think it's part of this question).
Upvotes: 1