Skip to content

Instantly share code, notes, and snippets.

@egomez99
Created April 10, 2012 21:57
Show Gist options
  • Save egomez99/2354898 to your computer and use it in GitHub Desktop.
Save egomez99/2354898 to your computer and use it in GitHub Desktop.
Take a screen shot
var win = Ti.UI.createWindow({
backgroundColor:'white'
});
win.add(Ti.UI.createLabel({
text:'A label that is being shown'
})
);
win.addEventListener('load', function()
{
Titanium.UI.orientation = Titanium.UI.LANDSCAPE_LEFT;
});
win.open();
function getOrientation(o)
{
switch (o)
{
case Titanium.UI.PORTRAIT:
return 'portrait';
case Titanium.UI.UPSIDE_PORTRAIT:
return 'reverse portrait';
case Titanium.UI.LANDSCAPE_LEFT:
return 'landscape';
case Titanium.UI.LANDSCAPE_RIGHT:
return 'reverse landscape';
case Titanium.UI.FACE_UP:
return 'face up';
case Titanium.UI.FACE_DOWN:
return 'face down';
case Titanium.UI.UNKNOWN:
return 'unknown';
}
}
var flipOrientation = getOrientation(Titanium.UI.orientation);
/*
Titanium.Gesture.addEventListener('orientationchange',function(e){
alert(e.orientation);
});*/
/*
var screenShotImage=null;
Titanium.Media.takeScreenshot(function(event){
var screenShot = event.media;
//screenShotImage.image = screenShot;
if (flipOrientation == 'landscape')
{
var tleft = Ti.UI.create2DMatrix();
tleft = tleft.rotate(90);
screenShotImage.transform = tleft;
}
});*/
var imageView = Ti.UI.createImageView();
Titanium.Media.takeScreenshot(function(event)
{
// set blob on image view
imageView.image = event.media;
win.setBackgroundColor('red');
var a = Titanium.UI.createAlertDialog();
// set title
a.setTitle('Screenshot');
// set message
a.setMessage('See screenshot of this page');
// set button names
a.setButtonNames(['OK']);
// show alert
a.show();
win.add(imageView);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment