0
votes

I have an image stored at /assets in my project folder and I am trying to read it using Ti.Filesystem.getFile(). The code prints the blob data in android but it prints undefined in iOS. Following function is called on Button click event https://pastebin.com/QgqLQPyz

function readImg(e) {
var localPath = '/butterfly.jpg';
var cachedFilename = Ti.Utils.sha1(localPath) + localPath.substr(localPath.lastIndexOf('.'));
console.log("cachedFilename:---"+cachedFilename);
var cachedFile = Ti.Filesystem.getFile(Ti.Filesystem.applicationCacheDirectory, cachedFilename);

if(!cachedFile.exists()){
    var blob = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, localPath).read();
    console.log("-----------blob in not exists:"+JSON.stringify(blob));
}

}

When the same image path is set in ImageView it gets displayed so the issue is not with path . What am I missing here ? pls help. Thank you.

1
This is because of app thinning, assets are put into an asset catalogue. Why do you need to read images like this if I may ask?Rene Pot
Thanks for your reply. I want to read image width and height from blob data and resize it accordingly using "blob.imageAsCropped" to fit in my imageview .Mario

1 Answers

0
votes

The best option so you don't have to do anything specific to the images at all (keep in mind, image manipulation is pretty heavy to do on runtime), is to use a module that was made for this purpose, av.imageview. This allows you to configure all kinds of content modes.

An option to get your code to work is to get the blob using the the getAsset method.

var blob = Ti.Filesystem.getAsset('/images/butterfly.jpg');

and then resize where you see fit. But I would advise you, if you do need to do this every time the app runs, then just resize once and store that resized image to be used after that. That way there will only be a single time the image needs resizing.