Android Drawable.createFromStream分配了过多的内存

| 我通过执行以下操作从http流创建Drawable。
    HttpClient client = new DefaultHttpClient();
    HttpGet get = new HttpGet(url);

    HttpResponse response = client.execute(get);

    InputStream is = response.getEntity().getContent();

    Drawable drawable = Drawable.createFromStream(is, \"offers task\");

    return drawable;
我的问题是Drawable.createFromStream分配的内存要多得多。我要下载的图片为13k,但是createfromstream调用分配了16mb的缓冲区,导致内存不足错误。
E/AndroidRuntime( 8038): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget(Heap Size=9066KB, Allocated=7325KB, Bitmap Size=16647KB)
还有其他人遇到这个问题吗?     
已邀请:
在android上加载外部图像的常见做法是根据托管ImageView的大小对图像进行下采样。 脚步: 1,下载原始图片。 2,使用BitmapFactory.decodeFile(filePath,options)方法获取图像的宽度和高度。
BitmapFactory.Options opt = new BitmapFactory.Options();
BitmapFactory.decodeFile(filePath, opt);
int width = opt.outWidth;
int height = opt.outHeight;
3,进行数学运算,训练一个sampleSize,并解码文件:
opt = new BitmapFactory.Options();
opt.inSampleSize = theSampleSizeYouWant;
img = BitmapFactory.decodeFile(filePath, opt)
为android编程就像地狱。 android团队似乎不了解java到底是什么。这些代码闻起来像MS C,在这种情况下,您首先需要传递一个结构以获取它的大小,自己进行内存分配,然后再次传递它并获得结果。几乎有成千上万的小陷阱需要特别注意才能显示网络图像。 (别忘了在不再需要图像后使用recyle()方法清除内存。androidgc很烂)     

要回复问题请先登录注册