Load images from device

I’m downloading images from web via Loader class, after successful download I’m saving the image to application’s cache. If someone tries to redownload image I load it directly from device instead of web. Again I’m using Loader class. Loading images takes about 400 miliseconds on my phone. However if I use BitmapData.loadFromBytes it takes only ~100 miliseconds…but it’s not asynchronous so my whole app freezes :confused: Is there a way to load images faster while still relying on asynchronous methods? I’m using legacy mode.

How would loading image using Thread class look like?

private function loadImage():Void
{
        var worker:Thread = Thread.create(function()
        {

            var main:Thread = Thread.readMessage(true);
            bdm = BitmapData.loadFromBytes(ba, null);
            onBytesComplete();
        });
        worker.sendMessage(Thread.current ());
	}

This code still freezes my tablet :frowning:

Update:
I guess I was wrong, this function works fine. On newer devices it works flawlessly. However on galaxy tab 3 image loads fast but there is a huuuge delay after calling addChild(new Bitmap(bdm)).

I believe that Assets.loadBitmapData uses a thread, though that won’t help with using a pre-downloaded image.

Without legacy, a Lime BackgroundWorker is an easy solution to this, though it’s a bit more complicated with legacy. Be aware, Thread.readMessage is global across all Haxe thread objects

1 Like