B4J Question Load Image - Multithreaded ? Possible ?

jmon

Well-Known Member
Licensed User
Longtime User
Hi,

Is it possible to load an image into an imageView on a separate thread?
I have lots of images to load and it's taking too much time to do the loadImageSample right now.

I'm thinking that the best solution would be to load them in a webView, but I was wondering if someone had a better idea?

Thank you.
Jmon.
 

Roycefer

Well-Known Member
Licensed User
Longtime User
Loading the images from your hard drive into RAM won't be sped up by multi-threading (and it might even be slowed down) though your overall program execution time might go down if you get that task off the main thread so that UI events can execute. Down-sampling an image (especially a large one) might be CPU-intensive enough to benefit from multi-threading. Loading the down-sampled image into an ImageView must be performed on the UI thread, which means it has to be single-threaded. If you choose to go the multi-threaded route, I suggest you don't use any more threads than you have Hyper-Threaded cores as you'll start to lose performance above that number.
 
Upvote 0

jmon

Well-Known Member
Licensed User
Longtime User
Thanks.

Yes my idea was to keep the app responsive while I load the images.

I thought also about having a list of image to load and load them one by one with a timer instead of all at the same time in a single loop.
 
Upvote 0

Roycefer

Well-Known Member
Licensed User
Longtime User
Yeah, a timer would work, as well. It'll probably take longer but your app would remain responsive.
 
Upvote 0
Top