【发布时间】:2016-07-26 14:06:29
【问题描述】:
我正在将大量图像加载到钛图像视图中。问题是在android中我遇到了内存问题。这是我将图像放入图像视图的功能。在这个函数中,我正在调整图像的大小。
exports.SetImg = function(img, hightFactor, widthFactor, viewObj, deviceWidth, deviceHeight) {
if (img != null && img != "") {
var IMGhight = 0,
IMGwidth = 0,
height = 0,
width = 0;
var imgTemp = Ti.UI.createImageView({
image : img
});
if (imgTemp != null) {
if (imgTemp.toBlob().height != null && imgTemp.toBlob().width != null) {
IMGhight = imgTemp.toBlob().height;
IMGwidth = imgTemp.toBlob().width;
height = alturaImg;
width = larguraImg;
if (height > deviceHeight * hightFactor) {
if (height > deviceHeight * hightFactor) {
height = deviceHeight * hightFactor;
width = (((deviceHeight * hightFactor) / IMGhight) * IMGwidth);
}
if (width < deviceWidth * widthFactor) {
width = deviceWidth * widthFactor;
height = (((deviceWidth * widthFactor) / IMGwidth) * IMGhight);
}
} else if (width > deviceWidth * widthFactor) {
if (width > deviceWidth * widthFactor) {
width = deviceWidth * widthFactor;
height = (((deviceWidth * widthFactor) / IMGwidth) * IMGhight);
}
if (height < deviceHeight * hightFactor) {
height = deviceHeight * hightFactor;
width = (((deviceHeight * hightFactor) / IMGhight) * IMGwidth);
}
} else if (height < deviceHeight * hightFactor) {
if (height < deviceHeight * hightFactor) {
height = deviceHeight * hightFactor;
width = (((deviceHeight * hightFactor) / IMGhight) * IMGwidth);
}
if (width < deviceWidth * widthFactor) {
height = deviceWidth * widthFactor;
height = (((deviceWidth * widthFactor) / IMGwidth) * IMGhight);
}
} else if (width < deviceWidth * widthFactor) {
if (width < deviceWidth * widthFactor) {
width = deviceWidth * widthFactor;
height = (((deviceWidth * widthFactor) / IMGwidth) * IMGhight);
}
if (hight < deviceHeight * hightFactor) {
hight = deviceHeight * hightFactor;
width = (((deviceHeight * hightFactor) / IMGhight) * IMGwidth);
}
}
var imagem = Ti.UI.createImageView({
width : width,
height : hight,
image : img
});
viewObj.add(imagem);
imagem = null;
imgTemp = null;
IMhight = null;
IMGwidth = null;
hight = null;
width = null;
img = null;
hightFactor = null;
widthFactor = null;
viewObj = null;
deviceWidth = null;
deviceHeight = null;
}
}
}
};
我已经为 GC 声明了所有变量为 null,但我仍然遇到内存问题。有人现在如何解决这个问题?
问题是我需要重复使用相同的图像来做其他事情,所以我需要它们来乞求。
【问题讨论】:
-
虽然您正在调整图像的大小,但它的权重将完全相同。所以我认为你必须为你的应用找到某种延迟加载解决方案。
-
大约 30 张图片,大小为 1024*800
标签: android memory-management titanium appcelerator