New2Android
New2Android

Reputation: 37

screenshots in android programmatically without actionbar

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

Answers (1)

Dmitry Zaytsev
Dmitry Zaytsev

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

Related Questions