LoadRawTextureData: not enough data provided

Hello, so i'm sending my sprite over the network by getting the texture from it, then converting it into a byte array

Then im sending the byte AND the size of the texture, but when i use LoadRawTextureData, it says the texture size is too big?, please help

This is the code that sends it

PhotonView.RPC("SetUserInfo", PhotonTargets.AllBufferedViaServer, textureBytes,  new Vector2(texture.width, texture.height));

and this is the code that assembles it again on the other end, but its also here where the error gets thrown

var objTexture : Texture2D = new Texture2D(textureSize.x, textureSize.y);
        objTexture.LoadRawTextureData(textureBytes);
        objTexture.Apply();

Just to be clear, this is how i'm getting the texture from the sprite

var textureBytes : byte[] = spriteIcon.texture.GetRawTextureData();

Bump

According to the docs: https://docs.unity3d.com/ScriptReference/Texture2D.LoadRawTextureData.html
You should specify more information to let Unity know what kind of Texture you are constructing from the raw byte array.

1 Like

I even tried this with no luck, still the same

icon = GameJolt.API.Manager.Instance.CurrentUser.Avatar;

var textureTemp : Texture2D = icon.texture;

                var textureOriginal : byte[] = textureTemp.GetRawTextureData();
                var textureCompressed : byte[] = CLZF2.Compress(textureOriginal);

                Debug.Log("original: " + textureOriginal.length + " | compressed: " + textureCompressed.length + " | size: " + new Vector2(textureTemp.width, textureTemp.height));

                var textureDecompressed : byte[] = CLZF2.Decompress(textureCompressed);

                Debug.Log("original2: " + textureDecompressed.length + " | compressed2: " + textureCompressed.length);

                var objTexture : Texture2D = new Texture2D(textureTemp.width, textureTemp.height);
                objTexture.LoadRawTextureData(textureOriginal);
                objTexture.Apply();
1 Like

Please see the attached project. works well for me.

2864847--209765--RawTextureData.zip (78.3 KB)

1 Like


just to be sure, does the code i've made work with jpeg? because its only when i use jpeg it doens't work


Nevermind, i got it working now!

The only thing i need to add was this little bit of code -.-'

TextureFormat.RGBA32, false
7 Likes