最好的方法从URL在Android的下载图像最好的、图像、方法、URL

2023-09-11 20:34:35 作者:苍山有井名为空

我用下面的方法来下载网址的单个图像

I'm using below method to download single image from url

public static Bitmap getBitmap(String url) {
    try {
        InputStream is = (InputStream) new URL(url).getContent();
        Bitmap d = BitmapFactory.decodeStream(is);
        is.close();
        return d;
    } catch (Exception e) {
        return null;
    }
}

有时候,我得到一个内存不足的异常。

Sometimes I get an outofmemory exception.

我无法赶上内存不足的异常。该应用程序将关闭。如何prevent呢?

I am unable to catch outofmemory exception. The app will close. How to prevent this?

是否有下载图像更好的方法也比较快?

Is there a better method for downloading images that is also faster?

推荐答案

我用这个库,它是真正伟大的,当你必须处理大量的图像。它下载他们异步,缓存它们等。

I use this library, it's really great when you have to deal with lots of images. It downloads them asynchronously, caches them etc.

对于OOM异常,使用this和this一流的大幅减少它们对我来说。

As for the OOM exceptions, using this and this class drastically reduced them for me.

 
精彩推荐
图片推荐