Shubham Seth Posted August 22, 2018 Share Posted August 22, 2018 how to load a BASE 64 image in phaser 3 ? I am doing on this way function preload() { var dataURI = '''data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQY............" var data = new Image(); data.src = dataURI; game.cache.addImage('image-data', dataURI, data); } function create() { game.add.image(0, 426, 'image-data'); } plicatibu 1 Link to comment Share on other sites More sharing options...
perseluspiton Posted August 22, 2018 Share Posted August 22, 2018 how about this.textures.addBase64(key, data); samme 1 Link to comment Share on other sites More sharing options...
Shubham Seth Posted August 23, 2018 Author Share Posted August 23, 2018 Adds a new Texture to the Texture Manager created from the given Base64 encoded data. @perseluspiton Link to comment Share on other sites More sharing options...
perseluspiton Posted August 23, 2018 Share Posted August 23, 2018 https://gist.github.com/psbolden/fdecf4ba95ba01a95c2ab20c799e30d8 Link to comment Share on other sites More sharing options...
gafami Posted August 27, 2018 Share Posted August 27, 2018 I have re-write your code a little bit. Hope it help. var platform; var counter = 0; function preload() { platform = this; /*var dataURI = '''data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQY............" var data = new Image(); data.src = dataURI; game.cache.addImage('image-data', dataURI, data);*/ } function create() { // Handle Base 64 Image From Here Not From PreLoad var dataURI = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQY............" platform.textures.addBase64('imgBase64', dataURI); // Loader to wait all base64 Image loaded platform.textures.on('onload', function() { counter++; }); // Timer check when all based64 assets have been loaded platform.customTimer = platform.time.addEvent({ delay: 500, callback: function callback() { // Adjust counter maximum as you ecpect. For now just one based64 assets need to be loaded only if (counter === 1) { // Destroy timer to save memory platform.customTimer.remove(false); // Add base64 image and position it platform.imgBase64Sprite = platform.add.sprite(game.config.width / 2, game.config.height / 2, 'imgBase64'); } }, callbackScope: platform, loop: true}); } plicatibu 1 Link to comment Share on other sites More sharing options...
Shubham Seth Posted October 30, 2018 Author Share Posted October 30, 2018 Yes it works fine and simplye you can do that before going to display load all the assets then add image Link to comment Share on other sites More sharing options...
khaica Posted December 9, 2019 Share Posted December 9, 2019 Hi everyone. I'm using base64 code, but why visual studio code can't read it. and the image is undefine when I run. Link to comment Share on other sites More sharing options...
Recommended Posts