-
-
Save artworker/da6d97c7ff1fb5a3e178 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment