Optimize loading of many images on iPad

后端 未结 1 328
被撕碎了的回忆
被撕碎了的回忆 2021-01-16 03:23

I\'m working on a project for the iPad where I\'m trying to simulate the rotation of a 3D-body with touch by switching pre-rendered images.

I\'m not the sharpest man

相关标签:
1条回答
  • 2021-01-16 04:07

    The first critical piece of information is that imageNamed is hopeless! It is well-known to be a dog. It's neither one thing or the other; it doesn't cache well and it tends to build up too much memory use. (Google up 100s of articles on this.) So, that's out.

    You will have to tell us exactly how many images you have, and exactly how big (KB or MB) each image is.

    Only then can one decide a successful strategy.

    To swap from one large image to another "properly", if you are swapping huge images over and over and if you have to worry about memory, you do this...

    [hugeImage.image release];
    hugeImage.image = [[UIImage alloc] initWithContentsOfFile:
               [[NSBundle mainBundle]
               pathForResource:@"bodyPart"
               ofType:@"png"]];
    

    that will properly get rid of the previous image and bring in the next one. NEVER, EVER use imageNamed -- it is specifically designed only for small (i.e. icon sized) interface-use (i.e., buttons, icons, etc) images.

    However again, nobody can help you until we know the precise number of images, and the precise size, and indeed how often per second or per minute you expect the images to be swapped. Hope it helps!

    ----- You went on to say ...

    "89 .png pictures ranging in size from about 70 K to 100 K"

    Good news, you're going to have no problem whatsoever. You can easily load those, and you can even do it fast enough in real time to make a 20 - 30 fps animation.

    Simply do exactly what I say above each time you swap from one to another, and you're done.

    (For the record, remember to load one first when you are initialising, so that the code fragment above works properly the "first time" it is used, you know. And if possible, release the last one when you're done.) Cheers.

    0 讨论(0)
提交回复
热议问题