简体   繁体   English

如何在没有OOM(内存不足)异常的情况下进行屏幕捕获?

[英]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. 因此很容易出现OOM问题。 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.Config.RGB_565代替Bitmap.Config.ARGB_8888

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

This reduces memory usage by half. 这样可以将内存使用量减少一半。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 KAFKA Stream OOM(内存不足) - KAFKA Stream OOM (Out of Memory) 如何在没有OOM异常的情况下将字节数组解码为位图 - how to decode byte array to bitmap without OOM Exception 从大表中检索所有记录时如何避免OOM(Out of memory)错误? - How to avoid OOM (Out of memory) error when retrieving all records from huge table? 捕获屏幕图像而不会出现屏幕捕获垃圾邮件 - Capture the screen image without screen capture spamming 获得Out of Memory Exception的根本原因是什么? 我们怎样才能克服这一点? - What is the root cause of getting Out Of Memory Exception? How can we overcome this? JVM 如何因 OOM 异常而死机? - How a JVM dies due to an OOM exception? 如何在java中列出200万个文件目录,而不会出现“内存不足”异常 - How to list a 2 million files directory in java without having an “out of memory” exception 防止CloudFoundry杀死OOM上的应用程序(内存不足) - Preventing CloudFoundry from killing an application on OOM (out of memory) 如何使用PrintWriter克服内存不足异常? - How to overcome out of memory exception with PrintWriter? 如何捕获AsyncTask中的内存不足异常 - how to catch a out of memory Exception in AsyncTask
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM