Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-10061] iOS: If we base64 encode and then decode an image blob, the blob loses the height and width property

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionInvalid
Resolution Date2012-07-23T10:29:37.000+0000
Affected Version/sRelease 2.0.2, Release 2.1.0
Fix Version/sn/a
ComponentsiOS
Labelscore
ReporterBetty Tran
AssigneeMax Stepanov
Created2012-07-20T11:23:15.000+0000
Updated2017-03-09T23:12:54.000+0000

Description

Problem

When we use Ti.Utils.base64encode() to encode an image blob and then use Ti.Utils.base64decode(), the height and width of the blob are 0. Prior to base 64 encoding the blob, we are able to get the correct height and width properties from the blob.

Test case



var win = Ti.UI.createWindow({
	backgroundColor : 'pink'
});

win.open();

var img = Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory, 'test.png');

var str_blob = img.read();
alert(str_blob.width);
alert(str_blob.height);

var str_64 = Ti.Utils.base64encode(str_blob);
var decoded = Ti.Utils.base64decode(str_64);

alert('Height: ' + decoded.height + 'Width: ' + decoded.width);

Expected behavior

The height and width properties should be available.

Comments

  1. Max Stepanov 2012-07-23

    base64decode returns a raw data(blob), no mime-type information available.
  2. Stephen Tramer 2012-07-23

    Occurs because when you base64-encode an image, what you're storing is the image's ORIGINAL size along with the blob, which is what is available. It would be possible to store a modified image as the blob, but that may not always be desired behavior for a number of reasons.
  3. Max Stepanov 2012-07-23

    Pedro, encode/decode !== serialize/deserialize Technically, what you need to do prior to reading width/height properties is decoded.mimeType = str_blob.mimeType, but we have no setter for mimeType in the platform. For the File.read, we get mimeType from file name, but it's not stored during encode/decode.
  4. Lee Morris 2017-03-09

    Closing ticket as invalid.

JSON Source