Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Downloading Transparent PNG's on Android turns the background black

$
0
0

Hi guys,

Can anyone shed any light on why using the Image Factory module to download and store images on Android, does it ignore the transparency on PNG graphics and give them a black background?

It works fine on iOS and everything is "as is".

Do I need to add anything to the download script to retain the transparency?

Help!

Here is my download script:

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();
 
}
Simon

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>