- Home /
Quality of Texture2D.LoadImage() is different from preloaded sprite asset
I have UI.Image in my scene. When I reference Source Image to Sprite asset, I have full resolution quality and it does not depend on QualitySettings > Texture Quality. But I need to replace this UI.Image to external png:
var texture = new Texture2D( 2, 2 );
texture.LoadImage( File.ReadAllBytes( path ) );
var rect = new Rect( 0, 0, texture.width, texture.height );
var pivot = _image.sprite.pivot;
_image.sprite = Sprite.Create( texture, rect, pivot );
After replacing in this way I'm getting UI.Image with sprite that depends on QualitySettings > Texture Quality. Can I create Sprite or Texture2D in some way that does not depend on this setting?
Answer by FIFTYTWO · Feb 28, 2017 at 07:43 AM
I've found the solution! It is needed to specify mipmap false in constructor of Texture2D. It seems by default it is mipmap and mipmaps use global quality settings. So, my texture creation now looks like:
var texture = new Texture2D( 2, 2, TextureFormat.RGB24, false );
Answer by FortisVenaliter · Feb 17, 2017 at 09:12 PM
The documentation seems to imply you can set the compression scheme in the texture object before calling LoadImage and it should respect that.