我想从 URL 获取图像并将其转换为可绘制的。我有这个方法,效果很好:
public static Drawable getDrawableFromUrl(String url) throws IOException {
Bitmap x;
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
connection.connect();
InputStream input = connection.getInputStream();
x = BitmapFactory.decodeStream(input);
return new BitmapDrawable(x);
}
除了一件事。当图像太大时应用程序崩溃。
E/dalvikvm-heap(12750): 13142360-byte external allocation too large for this process.
E/dalvikvm(12750): Out of memory: Heap Size=6023KB, Allocated=3177KB, Bitmap Size=2563KB, Limit=20480KB
E/dalvikvm(12750): Trim info: Footprint=6023KB, Allowed Footprint=6023KB, Trimmed=952KB
E/GraphicsJNI(12750): VM won't let us allocate 13142360 bytes
我可以以某种方式增加图像所需的内存吗?或者也许有办法解决这个问题?