Add an image from CoverflowView to Photo gallery
I've created a coverflowView with 40 different images which works fine. However, when a user clicks on one of these images I'd like it to save the image to the Photo Gallery - and this isn't working. I get a "Result of expression 'Titanium.Filesystem' [undefined] is not an object."; error message. Code below.
Is there anyone out there who has done something similar (or can work out what I'm doing wrong?). Any help much appreciated. Thanks. John
var win = Titanium.UI.currentWindow;
var images = [];
for (var c=0;c<40;c++)
{
images[c]='../images/imageview/'+c+'.jpg';
}
// create coverflow view with images
var view = Titanium.UI.createCoverFlowView({
images:images,
backgroundColor:'#000'
});
// click listener - save the image to the photogallery when image is clicked.
view.addEventListener('click',function(e)
{
if (e.index == 0) {
var f = Titanium.Filesystem.getFile('../images/imageview/'+c+'.jpg');
Titanium.Media.saveToPhotoGallery(f);
Ti.UI.createAlertDialog({title:'Image Saved',message:'This image has been saved to your photo gallery.', buttonNames:['Close']}).show();
} else { }
});
win.add(view);
4 Answers
-
We're having the same problem, just even simpler:
var current = Ti.UI.createImageView({image: url}); var blobImage = current.toImage(); var file = Titanium.Filesystem.createTempFile(); file.write(blobImage); return file.nativePath;
This isn't an answer, just some support for your question. The above should work pretty well to my knowledge.
Ti Dev: 1.2.1,
Ti Framework: 1.4.2 (and tried 1.5.0 continuous),
SDK: 4.2 -
Acutally, just last ditch did something, and this is likely the voodoo it takes to make things work with Titanium, but I changed the SDK from Continuous 1.5.0 to 1.4.2, did a build, stopped it, changed it back to continuous, and now it works.
Like I said, voodoo.
So do that, rub your belly and pat your head 3x and maybe you'll have the same luck we did =p
Oi, Appcelerator is a fickle beast sometimes :(
-
Actually is sort of a bug, I get this error with numerous things sometimes (scrollviews, labels you name it) just delete everything in the build folder and rebuild it fully that should work with these kind of errors
-
maybe a little late but if you delete the build folder and let it make this again everything seems to work :)