how to fast load high resolution image?

hello guys

I am trying to load very high quality images from the server. (4K image 8192 * 8192 ↑)

The problem is that this image is just one of many content.
I do not want the FPS to be lowered while loading this image. So, I wonder how you can increase the load speed while maintaining high quality.

Of course, I know that lowering the resolution or lowering the quality of the image will improve the loading speed accordingly.
But I would like to maintain very high quality.

If have a good idea or someone who has solved this, please help me.

Unity version - 5.6.0p3, 2017.1.0p1
Target platform - PC, Mac & Linux Standalone
PC - High specification

What are you using the image for? Would a coroutine work aka loading on a different thread?

This is to exhibit photos uploaded to the server by the user.

Try this

1 Like

이건 어쩌면 나에게 도움이 될수도 있을거 같네요. 코드를 살펴봐야 겠습니다.
도와줘서 고마워요

If at all possible, I think English is needed on the forums.
Translation: (Google Translate)
“This may be helpful for me. I need to look at the code.
thank you for helping me”

@sTonto If you find a solution it might be best to share on the forums, I am sure more people will need help with such things :smile: Glad it helped

Yes, use a coroutine as @Basen1 mentioned:

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//    GET WEB DATA COROUTINE
float fProgress = 0.0f;
private IEnumerator GetWebData_Coroutine(string sURL)
{
    //  START TIMER
    float K_F_NETWORK_TIMEOUT_MILLIS = 20000f;//20 SEC TIMEOUT
    Stopwatch oStopwatch = new Stopwatch();
    oStopwatch.Reset();
    oStopwatch.Start();
    bool bTimedOut = false;

    //  START WEB REQUEST
    fProgress = 0.0f;
    sURL = sURL.Replace(" ", "%20");
    WWW oWWW = new WWW(sURL);

    //  WAIT FOR WEB REQUEST
    for (;;)
    {
        fProgress = oWWW.progress;
        if (oWWW.isDone)
        {
            break;
        }
        if (oStopwatch.ElapsedMilliseconds > K_F_NETWORK_TIMEOUT_MILLIS)
        {
            bTimedOut = true;
            break;
        }
        yield return null;
    }

    //  FINISHED
    if(!bTimedOut)
    {
        HandleReceivedWebData(oWWW);
    }
}

Call it like this:

   string sURL = "http://www.xyz.com/texture.jpg";
   StartCoroutine(GetWebData_Coroutine(sURL));

You can display a progress bar, fProgress can be used per frame, it goes 0 … 1.

2 Likes

Thank you for translating my words into English.:slight_smile:

Thank you for letting me know about a nice feature called the stopwatch.
But what I want is the ability to load faster than the API provided by Unity…T-T

I doubt it’s the API that’s slow it’s probably your server. Under the hood unity www api runs on seperate thread.

Have you timed how fast it takes in a browser to load the image? Make sure you clear the browser cache.

would be interesting to know if there is any difference?

When testing with a 4K image, we found that it took 0.3-1.2 seconds.

How long did the same URL take using unity?

I personally would recommend (HIGHLY RECOMMEND), using the native image compression format per platform (e.g.: DDS, PVR )… strip their headers, and load directly to GPU via Texture2D.LoadRawTextureData

the reason why it takes so long to load if you are using JPEG or PNG is because of the decoder it has to run through to “get” to the native format to load to the GPU… there is no getting around it at all and can add 300ms per decode or more… been there, done that.

go with native images and be happy.

[edit]
to add… this should all be done outside of your download routine… just download your pre-processed images (DDS, or PVR… whatever platform specific image format, without their headers!)… and read in their byte array… load with the loadrawtexturedata method, check out the link above for the other steps, but I have solve this very problem. I guarantee it makes a huge difference. promise.

2 Likes

@tswalk this sounds promising but lets say I have a JPEG file, what exactly do I have to do to the image to get rid of their headers?

Based on what you’ve stated, you are downloading these from a server right?

Well… you are going to have to do some work on the JPEG on the server side to convert it to the native image file format (DDS or PVR).

Before loading it with Texture2D.LoadRawTextureData you must remove the header of the image from the byte[ ]. This can be done on either the server before sending, or on the device. You will want to do it on the server so that the client only needs to read the byte[ ] and load.

@tswalk - How can I convert jpeg or png to native format ? Is there any tool or software to do it ? How to remove the header ?

sorry, that’s why i get paid the big bucks.

1 Like