Skip to content

Instantly share code, notes, and snippets.

@alexshive
Created February 21, 2014 23:34
Show Gist options
  • Save alexshive/9145958 to your computer and use it in GitHub Desktop.
Save alexshive/9145958 to your computer and use it in GitHub Desktop.
// Works on 3.2.0GA
var win = Ti.UI.createWindow({
backgroundColor : '#ffffff',
exitOnClose : true // this makes it a HEAVYWEIGHT window
});
var myView = Ti.UI.createView();
var curBtn = Ti.UI.createButton({
color : '#000000',
title : 'Select Photo',
height : 'auto',
width : 'auto',
top: 10
});
var imageView = Ti.UI.createImageView({
width: 200,
height: 200,
backgroundColor: '#ccc'
})
myView.add(curBtn);
myView.add(imageView);
curBtn.addEventListener('click', function(e) {
try {
Titanium.Media.openPhotoGallery({
success : function(event) {
var intent = Ti.Android.createIntent({
action : "com.android.camera.action.CROP",
data : event.media.nativePath,
type : 'image/*'
});
intent.putExtra("outputX", 200);
intent.putExtra("outputY", 200);
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("scale", true);
intent.putExtra("return-data", true);
var activity = win.getActivity();
activity.startActivityForResult(intent, function(param) {
var iname = Ti.Android.EXTRA_STREAM;
if (param.resultCode == Ti.Android.RESULT_OK) {
if (param.intent) {
var imageData = param.intent.getBlobExtra("data");
imageView.image = imageData;
}
}
});
},
error : function(error) {
},
cancel : function() {
}
});
} catch(e) {
}
});
win.add(myView);
win.open();
@sphairo
Copy link

sphairo commented May 2, 2014

Ya he probado este codigo y todo funciona perfectamente sobre Titanium SDK ver. 3.2.3 GA

@sphairo
Copy link

sphairo commented May 2, 2014

Muchas gracias por este ejemplo, Saludos!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment