简体   繁体   English

如何确保请求的图像分辨率不会抛出内存不足异常

[英]How to make sure requested image resolution will not throw out of memory exception

有没有一种方法可以确保调用函数以获取图像不会太多而无法容纳到可用内存中?

int[] intBuf = util.getAbgrRect(page, x, y, w, h, wPix, hPix);

Basically any kind of guessing method is going to be unreliable. 基本上,任何一种猜测方法都是不可靠的。 You could make sure that you've got plenty of memory available on your system, and set some large enough hard limits that you declare shouldn't be exceeded. 您可以确保系统上有足够的可用内存,并设置一些足够大的硬限制,您不应声明超出这些硬限制。

If all else fails, you can always do the unthinkable and write 如果所有其他方法都失败了,您总是可以做不可思议的事并写

int[] intBuf = null;
try {
    intBuf = util.getAbgrRect(page, x, y, w, h, wPix, hPix);
} catch(OutOfMemoryError e) {
    // abort processing
}

It's not pretty, but it'll work. 它不是很漂亮,但是会起作用。 Just be careful. 请注意。

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

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