Created
December 15, 2013 04:26
-
-
Save MotiurRahman/7968866 to your computer and use it in GitHub Desktop.
Android: OutOFMemory Errors when using image compression, resizing or thumbnails on select devices like the Galaxy S2
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
| /* Hi I have tested this jira ticket. It's not a bug imageAsResized or imageAsThumbnail works properly on my android device. | |
| OutOFMemory Errors and app crash may be occurred server side coding. | |
| Testing Environment: | |
| Android SDK: 4.2.2 | |
| Titanium SDK: 3.1.3 | |
| Titanium CLI Version: 3.1.2 | |
| Steps To Reproduce: | |
| 1. Create a sample Project | |
| 2. Paste this code in app.js file | |
| 3. Click the button and successfully take a photo with imageAsResized or imageAsThumbnail without any crash. | |
| */ | |
| // Test Case | |
| var win = Ti.UI.createWindow({ | |
| backgroundColor : '#000', | |
| layout : 'vertical', | |
| navBarHidden : false, | |
| title : 'Take a Photo From Camara' | |
| }); | |
| var takePhoto = Ti.UI.createButton({ | |
| title : 'Take_Photo', | |
| color : '#000', | |
| width : Ti.UI.SIZE, | |
| height : 60, | |
| top : 10, | |
| }); | |
| var image = Ti.UI.createImageView({ | |
| top : 10, | |
| height : Ti.UI.SIZE, | |
| width : Ti.UI.SIZE, | |
| }); | |
| win.add(takePhoto); | |
| win.add(image); | |
| //win.add(anImageView); | |
| takePhoto.addEventListener('click', function() { | |
| fireUpTheCamera(); | |
| }); | |
| function fireUpTheCamera() { | |
| Titanium.Media.showCamera({ | |
| success : function(event) { | |
| var cropRect = event.cropRect; | |
| var photo = event.media; | |
| Ti.API.debug('Our type was: ' + event.mediaType); | |
| if (event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) { | |
| var aspectRatio = photo.height / photo.width; | |
| //image.setImage(photo.imageAsThumbnail(129, 0, 0)); | |
| image.setImage(photo.imageAsResized(640, 600 * aspectRatio), 0.5); | |
| } else { | |
| alert("got the wrong type back =" + event.mediaType); | |
| } | |
| }, | |
| cancel : function() { | |
| }, | |
| error : function(error) { | |
| // create alert | |
| var a = Titanium.UI.createAlertDialog({ | |
| title : 'Camera' | |
| }); | |
| // set message | |
| if (error.code == Titanium.Media.NO_CAMERA) { | |
| a.setMessage('Please run this test on device'); | |
| } else { | |
| a.setMessage('Unexpected error: ' + error.code); | |
| } | |
| // show alert | |
| a.show(); | |
| }, | |
| saveToPhotoGallery : false, | |
| allowEditing : false, | |
| mediaTypes : [Ti.Media.MEDIA_TYPE_PHOTO] | |
| }); | |
| } | |
| win.open(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment