I have a very long photo and I want to download it in Unity I get this error : ( Texture has out of range width / height ) what can i do

Viewed 456

I have a very long photo and I want to download it in Unity I get this error : ( Texture has out of range width / height ) what can i do

This is the picture : https://team1x1.com/wp-content/uploads/TeamX-upload/manga_5fddfe622f64e/5fddfe6239587/1/002.jpg

I downloaded the image and then saved it to the files and when it was called to the scene I get this error :

Texture has out of range width / height UnityEngine.ImageConversion:LoadImage (UnityEngine.Texture2D,byte[])

        byte[] fileData;
        fileData = File.ReadAllBytes(filePath);
        texture = new Texture2D(32, 32);
        texture.LoadImage(fileData); //At this line the error comes

Give me your opinion on how to overcome this problem ؟؟

1 Answers

Try passing in larger numbers into the new Texture2D(#,#); function. Its likely that the large image doesnt fit within a 32x32 2D texture, hence the error message "Texture has out of range width / height"

Try 64x64, or whatever the height/width for the large image is. The google chrome HTML inspector says that image is width = 57 and height = 969. both 57, and 969 are larger than 32, so a new Texture2D(32,32) will not fit.

Edit #1: Upon further research, it appears that your image may be too big for your format / gpu :

User Aras says " Yeah, today we clamp max Texture2D sizes to 16384. Since that's a common "max supported limit" on many GPUs & graphics APIs." https://forum.unity.com/threads/texture2d-has-out-of-range-width.501936/

The unity docs have this desclaimer: Note that not all graphics cards support all texture formats, use SystemInfo.SupportsTextureFormat to check. Also, only the Texture2D class supports texture creation from script with Crunch compression texture formats. https://docs.unity3d.com/ScriptReference/TextureFormat.html

Related