Question

My app has a bunch of images stored as blobs in the local SQLite Database. These images are taken with the device camera. I'm using Titanium Alloy, so the image was saved using the .save() method an Alloy Model.

I've started using the TiSocial module that can post an image to Twitter or Facebook. One its parameters is image and it has to be:

a local/remote path to an image you want to share

The image I want to use is set as the image property on an ImageView. The ImageView image is set like this: $.theImageView.image = args.the_image;, where args.image is the image blob, taken from the database collection.

I tried to take this image blob and set it as the image on the TiSocial module initialisation method:

Social.activityView({
    text: "Hello world! Take a look at this: " + args.name,
    image: args.the_image,
    removeIcons:"airdrop,print,copy,contact,camera"
});

Alternatively I tried to take use the image saved on the ImageView, like this:

Social.activityView({
    text: "Hello world! Take a look at this: " + args.name,
    image: $.theImageView.image,
    removeIcons:"airdrop,print,copy,contact,camera"
});

However neither of these worked, and no image appears in the Tweet or Facebook message dialogs. And no error appears in the console.

On the other hand, if I set the image property to an image saved in the assets folder, then it works just fine. For example:

`image: "an_image.jpg"`

I tried a solution mentioned in the comments below, which was to save the image to Ti.FileSystem, and then read the image from there. However, this still did not work.

Était-ce utile?

La solution 3

I had some luck by saving the file to the Ti.Filesystem, and then later retrieving it and using the .getNativePath() method:

function getImage() {
    var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, args.alloy_id + '.jpg');  
    return f.read();  
 }

var theImage = getImage();

Social.activityView({
    text: "Just tried this beer called " + args.name,
    image: theImage.getNativePath(),
    removeIcons:"airdrop,print,copy,contact,camera"
});

Autres conseils

You could try sharing remote images this way...

var largeImg = Ti.UI.createImageView({
        width : Ti.UI.SIZE,
        height : 'auto',
        image :'http://www.google.com/doodle4google/images/splashes/featured.png'
    });

var imageGoogle =largeImg.toBlob();

// share image
Social.activityView({
    status : "Hello world! Take a look at this: ",
    image : imageGoogle,
    removeIcons:"airdrop,print,copy,contact,camera"
});

then i would suggest to add one field called img_path in your database table because you can not get path from blob so when you store any blob to alloy model then also add its path to that model so you can retrieve it later and can share.

Hope you understand.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top