Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-15269] Blob image to byte array conversion is not working in SDK 3.1.0.GA

GitHub Issuen/a
TypeBug
PriorityLow
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
ComponentsAndroid
Labelsandroid
ReporterKeerthi Santhanam
AssigneeUnknown
Created2013-09-10T12:19:37.000+0000
Updated2018-02-28T20:04:06.000+0000

Description

I am trying to capture a image and convert the blob image to byte array. Application crashes during this conversion process. This piece of code is working fine in SDK 2.1.3.GA. Titanium.Media.showCamera({ allowEditing : true, success : function(e) { var blob = e.media; var kilobytes = (e.media.length) / 1024; Ti.API.info('[Media Image Size]' + kilobytes + '[KB]'); Ti.API.info('e :' + JSON.stringify(e)); if (e.media.length > 614400) { var imageview = Ti.UI.createImageView({ image : e.media }); if (e.width > e.height) { imageview.width = 800; imageview.height = 800 * (e.height / e.width); } else { imageview.height = 800; imageview.width = 800 * (e.width / e.height); } blob = imageview.toBlob(); } var blobAsKB = (blob.length) / 1024; Ti.API.info('[Resized Image]' + blobAsKB + '[KB]'); var fileName = 'Receipt-' + new Date().getTime() + '.JPG'; var newDir = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'Receipts'); if (!newDir.exists()) { newDir.createDirectory(); } var writeFile = Titanium.Filesystem.getFile(newDir.nativePath, fileName); writeFile.write(blob); writeFile = Ti.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory + '/Receipts/' + fileName); var blobObj = writeFile.read(); var encoded = Ti.Utils.base64encode(blobObj); var str = encoded.toString(); var bytes = [str.length]; for (var i = 0; i < str.length; ++i) { bytes.push(str.charCodeAt(i)); } ConvertedImage = '[' + bytes + ']'; alert('Image converted to byte array successfully'); }, cancel : function() { }, error : function(error) { var alert = Titanium.UI.createAlertDialog({ title : 'Sorry!' }); if (error.code == Titanium.Media.NO_CAMERA) { alert.setMessage('This device does not have a camera.'); } else { alert.setMessage('error: ' + error.code); } alert.show(); }, mediaTypes : Ti.Media.MEDIA_TYPE_PHOTO, saveToPhotoGallery : true, });

Attachments

FileDateSize
Allocation Failed.rtf2013-09-10T12:23:13.000+00005647

Comments

  1. Keerthi Santhanam 2013-09-10

    Application crashes with the error Allocation Failed - process out of memory. See Attachment

JSON Source