Home > other >  Unity GUI. DrawTexture problem
Unity GUI. DrawTexture problem

Time:09-22

Unity USES GUI. DrawTexture loading Pc local image when testing found that when the image is larger than 2 m shows the appearance of the pure color and when the picture is less than 2 m is displayed, do not know that the great god to have a good solution

Their tried a compressed images show and then again after failed

Now to post a code
Void the Start () {
StartCoroutine (" LoadImage ", "D: \ \ 345 JPG");
}
Void OnGUI ()
{
If (texture!=null)
{
GUI. DrawTexture (new the Rect (100, 100, 1000, 1000), texture);
}
}
Private IEnumerator LoadImage (string imagePath)
{
WWW WWW=new WWW (" file:///imagePath + ");

The Debug Log (imagePath);
If (==null www.error
{

}
The else
{
The Debug. LogError (" LoadImage>> www.error: + www.error ");
}
Yield return WWW.
Texture=www.texture;
}
Image information

The unity of the show effect

CodePudding user response:

Initialization texture has a problem?

CodePudding user response:

Look at the code, it is no problem
Then don't load the picture of more than 2 m...

CodePudding user response:

That is because the default maxTextureSize unity WWW loaded texture is 2048, your image size super, need to modify as follows:
Var texture=new Texture2D (www.texture.width, www.texture.height);//create a specified size texture
Texture. LoadImage (www.bytes); Load the texture data line

I hope to adopt
  • Related