Image Cropping for Android in Titanium

Posted By : Nitin Bhatt | 08-May-2015

In this example you will see how to crop image.

 

To implement image Cropping in Android , you need to download the latest module from the link "https://github.com/iotashan/TiTouchImageView/tree/master/android/dist" and include it in your 'tiapp.xml' file.

 

 

In this example, I have created cropView and define its maxZoomLength and minZoomLength, maxZoomLength and minZoomLength can be change according to the requirement, Image can be resize using pinch, zoom. 

 

Write this code in you 'app.js'.

 var TiTouchImageView = require('org.iotashan.TiTouchImageView');



var window = Ti.UI.createWindow({

backgroundImage : "screenBackground.png",

});



var view = Ti.UI.createView({

top : 10,

backgroundColor : 'red',

height : 40

});

window.add(view);



var label = Ti.UI.createLabel({

text : 'Crop Image',

color : 'white',

font : {

fontSize : "18sp",

}

});



view.add(label);



var cropView = TiTouchImageView.createView({

maxZoomScale : 6.0,

minZoomScale : 1.0,

zoomScale : 1.0,

height : 240,

width : 240,

image : '[email protected]',

borderColor : 'red'

});



window.add(cropView);



var cropButton = Ti.UI.createButton({

bottom : 40,

title : 'Crop',

borderRadius : 6,

backgroundColor : 'red',

color : 'white',

height : 40,

width : 80

});

window.add(cropButton);



cropButton.addEventListener('click', function(e) {

var cropImageView = Ti.UI.createImageView({

height : 240,

width : 240,

image : cropView.toImage()

});



window.remove(cropView);

window.add(cropImageView);

});



window.open();
 

 

 

About Author

Author Image
Nitin Bhatt

Nitin is an Assistant Project Manager specializing in iOS Application Development. He is an avid reader.

Request for Proposal

Name is required

Comment is required

Sending message..