4

I have a list of images encoded as ByteArrays from an API to be displayed in a TableView

Here is one of the ByteArrays

i'm not managing to display an image with it, nor saving a file or making a buffer or a stream buffer, those are some examples

var blobStream = Ti.Stream.createStream({ source: array, mode: Ti.Stream.MODE_READ });

or

var buff = Ti.createBuffer({value:array, length:array.length, type:Ti.Codec.CHARSET_UTF8});

and giving the array either to

Titanium.Utils.base64decode( array ); 
Titanium.Utils.base64encode( array ); 

crashes badly with "wrong type passed to function"

How can I make a blob out of a ByteArray and set it to an Imageview?

Zerho
  • 1,440
  • 4
  • 19
  • 39

1 Answers1

1

You can use this snippet to convert byte array in base64 string.

Decode the string with var imageBlob = Ti.Utils.base64decode(string);

and than set it in var image = Ti.UI.createImageView({ image:imageBlob });

miky91
  • 98
  • 7
  • Sorry I m new to Titanium and crating POC on this, can please tell me how to use thi snippet in .js file? how to pass my byte array got from json to this function? – Bhavana Vadodariya Jul 14 '15 at 13:46