简体   繁体   中英

How to do a screen capture without getting an OOM (out of memory) exception?

I want to screencapture and save a view.

I think I can create a bitmap as big as the view and draw the view on this bitmap. In this situation, the view's width is the same as the screen's width, and its height may be more than the screen.

So it is easy to get an OOM problem. Is there any way to avoid this problem?

If you don't need transparency, you can use Bitmap.Config.RGB_565 instead of Bitmap.Config.ARGB_8888 :

Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);

This reduces memory usage by half.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM