查看过大,呼吁getDrawingCache时融入绘画缓存() [英] View too large to fit into drawing cache when calling getDrawingCache()
问题描述
我想取的的LinearLayout内容的截屏。该布局包含滚动视图,可以是可变高度/宽度。这code正常工作时的布局是不是太大(即你不需要滚动非常关闭屏幕上看到的一切):
I'm trying to take a screenshot of the contents of a LinearLayout. The layout contains a scrollview that can be of variable height/width. This code works fine when the layout is not too big (i.e. you don't need to scroll very much off screen to see everything):
View v1 = (LinearLayout)theLayout;
v1.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
但是,如果我试图捕捉的LinearLayout很大,那么对v1.getDrawingCache一个空指针的应用程序崩溃()。
However, if the LinearLayout that I'm trying to capture is large, then the application crashes with a null pointer on v1.getDrawingCache().
有一个在logcat的一个错误:
There is an error in logcat:
05-11 13:16:20.999:W /浏览(17218):查看过大,以适应绘图 高速缓存,需要4784400字节,只有3932160可用
05-11 13:16:20.999: W/View(17218): View too large to fit into drawing cache, needs 4784400 bytes, only 3932160 available
我怎样才能正确地采取这种布局的屏幕截图?有另一种方式去它不使用这么多的内存?
How can I properly take a screenshot of this layout? Is there another way to go about it that doesn't use so much memory?
推荐答案
下面就是结束了工作,我捕捉到一个大屏幕外的视图中的全部内容:
Here's what ended up working for me to capture a large off-screen view in it's entirety:
public static Bitmap loadBitmapFromView(View v)
{
Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
v.layout(0, 0, v.getLayoutParams().width, v.getLayoutParams().height);
v.draw(c);
return b;
}
它类似于这里答案,但我用视图的宽度/高度创建位图
It's similar to the answer here, except that I use the view's width/height to create the bitmap
这篇关于查看过大,呼吁getDrawingCache时融入绘画缓存()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!