【发布时间】:2015-04-13 12:45:35
【问题描述】:
谁能解释为什么使用Image Factory module在Android上下载和存储图像,它会忽略PNG图形的透明度并给它们一个黑色背景?
它在 iOS 上运行良好,一切都“原样”。
是否需要在下载脚本中添加任何内容以保持透明度?
救命!
这是我的下载脚本,我正在使用 Titanium 3.5.1 GA 构建:
function getMarker(url, filename) {
// this will enable us to have multiple file sizes per device
var filename2 = filename.replace(".png", "@2x.png");
var filename3 = filename.replace(".png", "@3x.png");
var mapMarker = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'map_marker_icons', filename);
var mapMarker2 = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'map_marker_icons', filename2);
var mapMarker3 = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'map_marker_icons', filename3);
// now we need to download the map marker and save it into our device
var getMarker = Titanium.Network.createHTTPClient({
timeout: 30000
});
getMarker.onload = function() {
// if the file loads, then write to the filesystem
if (getMarker.status == 200) {
// resize the images into non-retina, retina and retina HD and only download and resize what is actyally required
var getOriginal = ImageFactory.imageWithAlpha(this.responseData, {});
var resized2 = ImageFactory.imageAsResized(getOriginal, {
width: 50,
height: 50
});
mapMarker.write(resized2);
Ti.API.info(filename + " Image resized");
//I ALWAYS NULL ANY PROXIES CREATED SO THAT IT CAN BE RELEASED
mapMarker = null;
} else {
Ti.API.info("Image not loaded");
}
// load the tours in next
loadNav();
};
getMarker.onerror = function(e) {
Ti.API.info('XHR Error ' + e.error);
//alert('markers data error');
};
getMarker.ondatastream = function(e) {
//Ti.API.info('Download progress: ' + e.progress);
};
// open the client
getMarker.open('GET', url);
// change the loading message
MainActInd.message = 'Downloading Markers';
// show the indicator
MainActInd.show();
// send the data
getMarker.send(); }
任何帮助将不胜感激!
西蒙
【问题讨论】:
-
如果你要保存
getOriginal,它也有变化吗? -
是的,我也试过了,不高兴,忘了我把它放在那里了,但是它仍然以黑色背景下载
-
那么不要使用 ImageFactory 来下载文件。我不知道钛,但应该有一些东西可以将 responseData 直接定向到我希望你的文件/输出流。
标签: android titanium png appcelerator appcelerator-mobile