- Home /
How to import a high resolution Image file
Ok so i have been having a problem with unitys auto compression for files with the pixel size higher than 1089 x 4096. I am trying to import a image that is going to be used as the 2d ground and its pixel size is 4800 x 18048. Everytime i import this image it auto compresses and looks horrible. My question is, is there a way to import image files of any size and bypass the auto compression because i need this to work so my map looks the way it was intended to look. Thankyou
Answer by robertbu · Aug 22, 2014 at 07:39 PM
The WWW class will load files bigger than 4K. While I've not specifically tested this scenario (I'm away from my desktop), you should be able to put the file in StreamingAssets folder:
http://docs.unity3d.com/Manual/StreamingAssets.html
You will use the 'file://' protocol. This should work in mobile and desktop, but I doubt it will work on a web build. For a web build, you can pull it off the server.
So how do i import this assest and apply it to a game object that is the same size i said earlier for the img. Because im at a loss on how to use the strea$$anonymous$$g folder
Ultimately you need to thrash around and figure things out, but I'll give you a recipe and a bit of code to get you started:
Create a Assets/Strea$$anonymous$$g Assets folder
Put a large image in the folder. $$anonymous$$ine image was named 'LargeImage.jpg' and was 5000 x 1000.
Crate a Quad (GameObject > Create Other > Quad). Size the quad as appropriate. Using the aspect ratio of the image to be loaded is best.
Create a material for the Quad. I used Unlit/Texture for the shader and had the texture set to 'none'.
Attach the following script to the Quad
pragma strict
function Start() { var path = "file://"+Application.dataPath+"/Strea$$anonymous$$g Assets/"+"LargeImage.jpg";
var www = new WWW(path); yield www; if (!String.IsNullOrEmpty(www.error)) { Debug.Log(www.error); return; } renderer.material.mainTexture = www.texture; }
The path specifier will vary some from platform to platform. You can get most of that from the reference page for Strea$$anonymous$$g Assets. The path above was tested in the Editor on a PC.
There are other ways of doing the load. For example, rather than yielding, you can do a while(!www.isDone) loop. Your app will hang until the load, but the load will be faster. It all depends on how you need to structure your code. There is also a WWW.LoadImageIntoTexture() function that can be useful for certain kinds of setups.