我正在將很多圖像加載到鈦圖像視圖中。問題是,在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;
}
}
}
};
我已經將所有變量聲明爲null,但對於GC仍然存在內存問題。現在做一些如何解決這個問題?
的問題是,我需要重新使用別的東西相同的圖像,所以我需要他們的蜜蜂求。
儘管您正在調整圖像大小,但重量完全相同。所以我認爲你必須爲你的應用程序找到某種惰性加載解決方案。 –
什麼是「很多」 –
約30張圖片,大小爲1024 * 800 –