如下:
1.View.setDrawingCacheEnabled(true);
bitmap = scrollView1.getDrawingCache();
View.setDrawingCacheEnabled(false);
return bitmap;
2. bitmap = Bitmap.createBitmap(View.getWidth(), View.getHeight(), Bitmap.Config.RGB_565);(假如要对Bitmap进行比如毛玻璃效果的模糊,就不能使用RGB_565,得使用占用内存更多的ARGB_4444或8888)
Canvas canvas = new Canvas(bitmap);
View.setVisibility(0);
View.draw(canvas);
return bitmap;
以上两种方法适用于大部分VIEW , 不过只能截到View在屏幕的可视部分
优缺点:
从内存使用上,1比2更好 ,2的 createBitmap 方法更有可能会引起OOM
从自定义的角度上看,2更灵活