防止加载图片内存溢出的方法

防止加载图片内存溢出的方法:

private Bitmap getBitmapFromUrl(String url) {
        Bitmap bitmap = null;
        try {
            URLConnection conn = new URL(url).openConnection();
            conn.setConnectTimeout(CONNECT_TIMEOUT);
            conn.setReadTimeout(READ_TIMEOUT);

			BitmapFactory.Options opt = new BitmapFactory.Options();
			opt.inPreferredConfig = Bitmap.Config.RGB_565;
			opt.inPurgeable = true;
			opt.inInputShareable = true;
               
            bitmap = BitmapFactory.decodeStream((InputStream) conn.getContent(), null, opt);
        } catch(Exception e) {
            e.printStackTrace();
        }
        return bitmap;
    }

http://blog.csdn.net/huangbiao86/article/details/8072128

你可能感兴趣的:(防止加载图片内存溢出的方法)