Sprite.Create on Iphone behaves strange
Hello everyone. I have a drawing app for android, and I am trying to port it to iOS. I have encountered some strange problems. On iPad2 everything works almost perfectly, but when I launch my app on iPhone 4 there is a significant problem. In my app I download textures from server as a byte array, convert it into Texture2D and then call Sprite.Create. On iPhone texture2D is somewhy stretched on the recttransform of the image too much, and I can't figure why. Here is my code:
Sprite LoadSpriteFromFile(string fname) {
Texture2D tex = null;
byte[] fileData = File.ReadAllBytes(fname);
tex = new Texture2D(2, 2);
tex.LoadImage(fileData); //..this will auto-resize the texture dimensions.
return Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f));
}
And this works fine everywhere(including iPad) except iPhone. Here's the picture that I get:
And here is how it works on other devices and what I need from it:
I've tried to do following: Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f), 100, 0, SpriteMeshType.FullRect)
This helped a little, but part of texture is still cut. Any ideas?
Answer by Lazybones94 · Dec 08, 2015 at 03:49 PM
Solved this issue. It appeared that iOS does not support the DXT compression format that is set by default. I changed it to PVRTC_RGBA4 and this solved my problem. Or maybe canceling mip map creation helped, I am not sure, anyway, creating Texture2D with following code helped:
tex = new Texture2D(2, 2, TextureFormat.PVRTC_RGBA4, false);
thanks man! solved my problems too! thanks!! saved my life (or my night haha!)