Ads

Tuesday, March 6, 2012

Titanium copy image to Clipboard

Titanium provides Clipboard functionality. So that we can able to copy images and texts in Clipboard.
Let assume you have some image files in local file system, by using below code you can able to copy image to Clipboard.


var currIamge = 'test.jpg' // mention your image path and name
var imageFile = Titanium.Filesystem.getFile(currIamge);
var imageBlob = imageFile.toBlob(); // convert image file into blob using toBlob() method
Ti.UI.Clipboard.setData('image/jpg',imageBlob);


PS : Tested with iPhone and it works fine

2 comments:

  1. what about remote images or images in a scrollableview?

    ReplyDelete
  2. You can use toImage() method for convert your remote image view or scrollableview to blob data.

    var blobObj = temoteImageView.toImage(); // convert image view to blob

    Ti.UI.Clipboard.setData('image/jpg',blobObj);

    hope this helps you

    ReplyDelete