-
-
Save ypbnv/066245e8a5b4fc4c293a3df60e6c652c to your computer and use it in GitHub Desktop.
Workaround
This file contains 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
var win1 = Ti.UI.createWindow({ | |
//backgroundColor : 'red', | |
barColor : "#800000", | |
layout : "vertical" | |
}); | |
// Create a Button. | |
var btn1 = Ti.UI.createButton({ | |
title : 'Camera Open', | |
height : 100, | |
width : 100, | |
backgroundImage : "motiur.jpg", | |
top : 50 | |
}); | |
var ImageFactory = require('ti.imagefactory'); | |
var image1 = Ti.UI.createImageView({ | |
top : 20, | |
height : 'auto', | |
width : 'auto' | |
}); | |
var image2 = Ti.UI.createImageView({ | |
top : 20, | |
height : 'auto', | |
width : 'auto' | |
}); | |
function takePicture() { | |
Ti.Media.showCamera({ | |
//function to call upon successful load of the gallery | |
success : function(e) { | |
Ti.API.info("TakeTransactionImage: Success."); | |
if (e.mediaType === Titanium.Media.MEDIA_TYPE_PHOTO) { | |
Ti.API.info("TakeTransactionImage: Success. Was a photo."); | |
//e.media represents the photo or video | |
//sImageName = GetRandomFileName(); | |
image1.setImage(e.media); | |
win1.add(image1); | |
Ti.API.info('TakeTransactionImage(1)'); | |
var wid = (e.media.width) / 8; | |
var hei = (e.media.height) / 8; | |
//RESIZE IMAGE - HERE IS DIVIDING THE IMAGE DIMENSIONS BY 4 | |
Ti.API.info('TakeTransactionImage(2) image1.width=' + wid + "\n" + "Image1.height:" + hei); | |
Ti.API.info('ImageFactory.QUALITY_MEDIUM = ' + ImageFactory.QUALITY_MEDIUM); | |
//THIS IS THE LINE THAT TRIGGERS THE OUT OF MEMORY ERROR | |
var newImage = ImageFactory.imageAsResized(e.media, { | |
width : wid, | |
height : hei | |
}); | |
image2.setImage(newImage); | |
win1.add(image2); | |
//var f = ""; | |
var filename = new Date().getTime() + "-ea.jpg"; | |
var f = Ti.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, filename); | |
f.write(newImage); | |
Ti.API.info('TakeTransactionImage(4) f.nativePath = ' + f.nativePath); | |
} | |
//image1.remove(image); | |
//image2.remove(newImage); | |
newImage=null; | |
}, | |
cancel : function(e) { | |
callback(e, null); | |
}, | |
error : function(e) { | |
callback(e, null); | |
}, | |
saveToPhotoGallery : false, // save our media to the gallery | |
//mediaTypes : [type] | |
}); | |
} | |
btn1.addEventListener('click', function(e) { | |
if (!Ti.Media.hasCameraPermissions()) { | |
// request permissions to capture media | |
Ti.Media.requestCameraPermissions(function(e) { | |
// success! we can capture media! | |
if (e.success) { | |
takePicture(); | |
// oops! could not obtain required permissions... | |
} else { | |
Ti.API.error('could not obtain camera permissions!'); | |
} | |
}); | |
} else { | |
// yay! we already have permissions! | |
takePicture(); | |
} | |
}); | |
win1.add(btn1); | |
win1.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment