Titan ByteArray for Blob Image

I have a list of images encoded as ByteArrays from the API that will be displayed in the TableView

Here is one of ByteArrays

I am unable to display an image with it without saving the file or creating a buffer or stream buffer, these 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 an array either

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

bad with "wrong type passed to function"

How can I make a blob from ByteArray and set it to Imageview?

+4
source share
1 answer

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

var imageBlob = Ti.Utils.base64decode(string);

var image = Ti.UI.createImageView({ image:imageBlob });

+1

Source: https://habr.com/ru/post/1536585/


All Articles