gpt4 book ai didi

android - MyLinearLayout.getDrawingCache() 给出 NullPointerException

转载 作者:太空狗 更新时间:2023-10-29 14:27:48 26 4
gpt4 key购买 nike

编辑:

没关系,这样就可以了

TopRatedPage.setDrawingCacheEnabled(true);
TopRatedPage.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
TopRatedPage.layout(0, 0, TopRatedPage.getMeasuredWidth(), TopRatedPage.getMeasuredHeight());
TopRatedPage.buildDrawingCache(true);
Bitmap screenshot = Bitmap.createBitmap(TopRatedPage.getDrawingCache());
TopRatedPage.setDrawingCacheEnabled(false);

旧的:

我正在尝试从布局中截取屏幕截图,就像这样。

LinearLayout TopRatedPage = (LinearLayout)inflater.inflate(R.layout.toprated, null);
...
Bitmap screenshot;
TopRatedPage.setDrawingCacheEnabled(true);
screenshot = Bitmap.createBitmap(TopRatedPage.getDrawingCache()); // Caused by: java.lang.NullPointerException
TopRatedPage.setDrawingCacheEnabled(false);

知道我做错了什么吗?

谢谢!

编辑:也试过这样,它不会抛出错误,但给出了一个空位图。

Bitmap screenshot = TopRatedPage.getDrawingCache();

最佳答案

试试这个,让我知道会发生什么......

LinearLayout TopRatedPage = (LinearLayout)inflater.inflate(R.layout.toprated, null);
Bitmap screenshot = Bitmap.createBitmap(LinearLayout .getWidth(), LinearLayout .getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(screenshot);
LinearLayout.draw(c);
imageView.setImageBitmap(screenshot);

如果可能的话,使用,

View captureView = null;
captureView = inflater.inflate(R.layout.toprated, null);
Bitmap screenshot = Bitmap.createBitmap(captureView.getWidth(), captureView.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(screenshot);
captureView .draw(c);
imageView.setImageBitmap(screenshot);

关于android - MyLinearLayout.getDrawingCache() 给出 NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10278717/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com