[HTML5] BitmapData.fromBase64 returns null

What I am doing wrong? Base64 string is valid and can be checked here:

var base64:String = "iVBORw0KGgoAAAANSUhEUgAAASAAAABgCAQAAAAXpWfTAAABhGlDQ1BzUkdCIElFQzYxOTY2LTIuMQAAKJF1kblLQ0EQh78kSjxRMIWFRQpJISoaJWinBvEghBAVvJrkmUPI8XgvImJpYZsihQc2BrGx1k78BwRBUCsRbMVCwUbkOZsEEsTMsrvf/nZmdncW7MspLW02DEE6kzPCM1Pu5ZVVt/MFp7RmOvFENFOfDIUC1LWvB2xqvh9Quer7/WutGzFTA1uT8ISmGznhWeHgdk5XfCDs0pKRDeEL4X5DLij8pPRomd8UJ0psVzldxmLYL+wSdidqOFrDWtJIC48K96ZTW1rlPuolbbHM0oLSpfdgEmaGKdzMMY0fH8OMy+hjAC+DsqJOvLcUHyQrsZqMOjsYbJIgSY5+Ubcke0zmuOgxaSnxEFN/8Le2ZnzEWz6hbR4aXy3rsw+cx/Czb1nfp5b1UwSH1OWmUI3PFmDsXfR8Ves9gY49uLyuatEzuMpD97MeMSIlySHdHo/Dxzm0r0DXHbSsletW2af4CIu7ELiFwyPwiH/H+i/bgGcnxUElmgAAAAlwSFlzAAAhOAAAITgBRZYxYAAADHVJREFUeNrtXHlwVEUa/xIg4QgElWUVV6QWKigC4oGgeBWWFLC4oKy43oQA1ioqCZISEYQShUJcq2CVACogSwm7W5QYqV2F2swkk4MQmJCQi0km5JxMDnKfk8lsv+6eN2/IS5iXTaaf1Pfrf2be1d/7+ve6v6O7ARAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCD6CTeTgkD0EQ9BEykPoSIQfcN/wEXKv391cgfCLFgJmyEGfiQlhvxaSY4EYoP6F5MofaQy8Vcj8xBYCPvAJkuuLDZyZiG5AuEn7JJV/9mvQt4AWAb5qtRRlnxyVQA27sBjGFyVlV5D/ukdj0KqhyajOxbYVxdtsRzIOpC1xbK6aIF9dIeCRKn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dy80xBlx3e1dVni2d/lWp9u7TIMdbKK9olSBASJVUqPPEGd+mjhRx7DpTBst8+2DPbzvYsHFT/LcBNqWx4OG8jWDuxbYN1r4nMRbdND5R7kzfCGO8JJY1Q2mYs3hJSGeDaYidb7B1ERYQOzTD+EdmKuy/Y5OsL5bJ1kJn5Ju9G3p98RG9+YKE1ngfA05sx2qut3zni7e5Zot7ubbVxVvtuzP2p+12bKqeL49VJl8PItb3PWP62j1IoIJXuKdeiiLTZ+6IBHoJzb1tYnP8wmGlyHR674CnWygGwDPg+W6m2xayFW4uV2/wLONbxPEwL1e5/bx+TaEQHy+jHe6cQa5wrOH1iTdvNMQ0vHH9LjNbww5i9v89htC6feaTYam7nMIZzBLpyixMJFbR/eq3P82NfYsfpmDqK1vnUXsh02wF06Sspf8isCNxgcCI+HOHrvzRJZgjbTy4a2nYeNO8hQEohtepi57G3ftX0KFILRGV6oUvlkwKgShFdtlAn2KykBoxwQeOOwidg4C0QfEUgL9iIpA9A0zoI6UGagIRF8xghQEAoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgRgo/A/RnViO4KzCVgAAAABJRU5ErkJggg==";
var bd:BitmapData = BitmapData.fromBase64(base64, "image/png");
trace(bd); //null

Oh. It doesn’t work for html5

public static function fromBase64(base64:String, type:String):BitmapData
	{
		#if (js && html5)
		return null;
		#else
		var bitmapData = new BitmapData(0, 0, true, 0);
		bitmapData.__fromBase64(base64, type);
		return bitmapData;
		#end
	}

Any other solutions to embed image to source?

If I use metatag @:bitmap, I can create BitmapData and Bitmap.
But I cannot create Starling Texture for some reason from this bitmapdata. It’s just invisible.

var bytes = Base64.decode(base64);
var loader = new Loader();
function onComplete(e:Event)
{
	var bm = cast(loader.content, Bitmap);
}
function onError(e:UncaughtErrorEvent) {}

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
loader.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onError);
loader.loadBytes(bytes);
1 Like