[英]Android bitmap - out of memory
I have a problem with a function that I implemented. 我实现的功能有问题。 On some phones I get a out of memory error. 在某些手机上,出现内存不足错误。
private Bitmap getIconMarkerOfPlayer(Player p) {
Drawable drawable = getIconOfPlayer(p);
Bitmap img = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_4444);
Canvas canvas = new Canvas(img);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
drawable.draw(canvas);
final float scale = this.getResources().getDisplayMetrics().density;
int heigthPixels = (int) (24 * scale + 0.5f);
int widthPixels = (int) (24 * scale + 0.5f);
return Bitmap.createScaledBitmap(img, widthPixels, heigthPixels, false);
}
The getIconMarkerOfPlayer(Player p)
function gives a "programmed" drawable depending on the player's status (dead, alive, offline, ...) and its color. getIconMarkerOfPlayer(Player p)
函数根据播放器的状态(死,活着,离线,...)及其颜色提供“编程的”可绘制对象。 Each player has a unique color assigned to it in the early games. 在早期的游戏中,每个玩家都具有唯一的颜色。
How can I resize my bitmap from a Drawable
object without having a out of memory error? 如何在不出现内存不足错误的情况下从Drawable
对象调整位图的大小?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.