I have an image's Blob and want to convert it into Bitmap image to use android Canvas, Path and Paint in appcelerator Titanium. I went through appcelerator docs but couldn't find any method that allows me to convert directly. I tried converting blob to Base64 string and then create the bitmap object using android native methods through hyperloop but was unsuccessful.
Then I tried converting base64 to byte array and create bitmap using this code by using Hyperloop but bitmap is empty :
var BitmapFactory = require('android.graphics.BitmapFactory');
var ByteArrayInputStream = require("java.io.ByteArrayInputStream");
var stringToSaveInDatabase = Ti.Utils.base64encode(newBlob).toString();
var bytes = [];
for (var k = 0; k < stringToSaveInDatabase.length; k++) {
bytes.push(stringToSaveInDatabase.charCodeAt(k));
}
var arrayInputStream = new ByteArrayInputStream(bytes);
var bitmap = BitmapFactory.decodeStream(arrayInputStream);
var istream = new ByteArrayInputStream(new String(blob.toBase64().toString()).getBytes(StandardCharsets.UTF_8)); console.log("istream: " + istream); console.log("bmp: " + BitmapFactory.decodeStream(istream));
but the decodeStream returnsnull
at the end. That might be the case in your example too. You could save the image first and then use this to load that resource: jira.appcelerator.org/browse/… – miga