截图中的Andr​​oid编程没有动作条截图、动作、Andr、oid

2023-09-07 01:02:26 作者:励志当学霸

我试图将此code得到一个视图的截图没有动作条:

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));

请看一看这个项目:https://github.com/valerio-bozzolan/AcrylicPaint/blob/master/src/anupam/acrylic/EasyPaint.java任何帮助将是非常美联社preciated!

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!

更新:

我在显示java.lang.NullPointerException这行:

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

新年快乐!

推荐答案

如果您分配查看编程,那么你已经拥有了它:

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).