【发布时间】:2018-03-10 23:13:52
【问题描述】:
我在一项活动中使用了 2 种资源:
1 个圆形图像,如下所示:
String image = dataSnapshot.child("thumb_image").getValue().toString();
Picasso.with(pilotProfileImage.getContext()).load(image)
.placeholder(R.drawable.pilot_default).into(pilotProfileImage);
当 thumb_image 是存储在 Firebase 存储中的图片时。
另一个资源:
mImage.setBackgroundResource(R.drawable.m_air);
虽然R.drawable.m_air 是一个保存在我的drawable 文件夹中的drawable
我收到了
java.lang.OutOfMemoryError: 无法分配 14745612 字节分配,10530520 可用字节和 10MB 直到 OOM
我已经看到Bitmap 的解决方案,但我没有在这里使用位图。
我试过了
mDroneImage.setImageBitmap(decodeSampledBitmapFromResource(getResources(), R.drawable.mavic_air, 100, 100))
在这个解决方案中:Strange out of memory issue while loading an image to a Bitmap object
但应用仍然崩溃。此外,它不能解决 firebase 图像问题。
我该如何解决?
编辑: 在文档中找到了 firebase 问题的答案: https://github.com/codepath/android_guides/wiki/Displaying-Images-with-the-Picasso-Library
【问题讨论】:
-
图片分辨率是多少?
-
Firebase' 图片:2400*2400 jpg ,drawable:640*640 png
-
好吧,我用过:Picasso.with(pilotProfileImage.getContext()).load(image) .fit().placeholder(R.drawable.pilot_default).into(pilotProfileImage);添加了 fit(),并且还减少了占位符的大小 - Pilot_default 到小于 500dx,它解决了问题。可以做的另一件事是减小可绘制图片的大小,但目前它可以在没有它的情况下工作
-
这是一个不相关的 Firebase 存储问题。你试图在内存中放入一个巨大的图像。
标签: android firebase out-of-memory android-image