1

I have app similar to sample app PhotoScroller, e.g. lot of large images (2048x1536) in scrollview. I am not using tile approach as I don't like that partial load effect. I would like to show whole image at once. I am loading images in background thread. When I try to use loaded image in UIImageView for the first time, it blocks main thread for half a second even tho it is already in memory.

I used profiler to see where this lag is coming from but I couldn't find any useful information there.

Is iOS copying image data when it is used for the first time or something like that? Can I somehow do that in background thread as well?

EDIT: when I scroll there and back again and use that same UIImage second time, there is no delay

Lope
  • 5,388
  • 4
  • 30
  • 40
  • If UIImageView continues to act up you could try [adding your UIImage directly into a CALayer.](http://stackoverflow.com/questions/1564940/how-to-display-an-image-or-uiimage-with-an-plain-calayer) – Joel Kravets Feb 10 '12 at 00:26
  • Loading a 2048x1536 image in memory is stupid, that's 12Mb ram used for 1 image. Reduce the images to the target size using ImageIO then display them. – Nyx0uf Feb 10 '12 at 15:37

2 Answers2

0

Try to make image in background thread too. Do you loading image from inet or locally? bundle or custom path?

NeverBe
  • 5,213
  • 2
  • 25
  • 39
  • what do you mean by "make image in background thread" ? whole uiimage is create in background. Should I create UIImageView in background as well? Images are loaded from local path (not bundle) – Lope Feb 09 '12 at 22:39
0

I think I solved it. Turns out when ios loads UIImage from disc or web, it doesn't load it in correct format. So when you want to display it, ios has to reformat this image into the format that he can use. This reformating can cause visible stuttering when image is big enough.

To prevent this, you need to reformat UIImage after it was loaded and you can do that safely in background (as far as I know). This link show how to do it.

Lope
  • 5,388
  • 4
  • 30
  • 40