Quantcast
Channel: Questions in topic: "javascipt"
Viewing all articles
Browse latest Browse all 1875

Base64 to texture decoding, js -> webgl

$
0
0
I'm building webgl application in unity and I want to allow user to import image (png).
Javascript: function process(input) { let file = input.files[0]; let reader = new FileReader(); reader.onload = function (e) { unityInstance.SendMessage('Phone', 'SetImageFromBase64', e.target.result); }; reader.readAsDataURL(file); } C#: private void Awake() { SetImageFromBase64(); } public void SetImageFromBase64(string str = "data:image/png;base64,iVBORw0KGg(...)") { var bytes = Convert.FromBase64String(str.Substring("data:image/png;base64,".Length)); var tex = new Texture2D(2, 2); tex.LoadImage(bytes); tex.wrapMode = TextureWrapMode.Clamp; tex.Apply(); meshRenderer.material.SetTexture(MainTex, tex); } And when application is started, image is properly loaded, but when I try to load same image using javascript all I'm getting is black texture. Do anyone have an idea why this is happening?

Viewing all articles
Browse latest Browse all 1875

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>