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

local file storage - create, save and load an image / photo

$
0
0

hi, eventually my goal is to * take a photo * save the photo to the local directory * call that photo so the user can view it another time

Right now just working through local storage read and write which is all very new to me, so right now just trying to create an a new image (from my resources/images folder) and save it out, then view it on screen but not quite working

here's the code I'm working with

var tempImage = Ti.UI.createImageView({
    image: '/Images/back.png'
});
 
var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'newImage');
f.write(tempImage); // write to the file
the function checkImages loops through a small view with 3 children (buttons which should display the image or photo as a thumbnail), but right now its not displaying anything
function checkImages(){
        length = camView.children.length;
        for (var i = 0, length; i < length; i++){
 
                if(Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'new2Image') === null){
                    // display the image type
                    Ti.API.info("no image found on storage")
                    camView.children[i].backgroundImage = '/Images/' + camView.children[i].id + '.png';
                }
                    // else there is a saved photo, so display the thumbnail
                else {
                    Ti.API.info("image found on storage");
                    var f = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, 'new2Image');
                    var blob = f.read();
                    camView.children[i].backgroundImage = blob;
                    Ti.API.info(camView.children[i].backgroundImage);
                }
 
        }
    }
when i run the function its definitely running the "else" statement as I can see on the console "Image found on storage" and the "backgroundImage" for the camView children comes up as <null>

Thanks for your help


Viewing all articles
Browse latest Browse all 8068

Trending Articles



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