drmcmmssrs
drmcmmssrs

Reputation: 23

How to reduce the memory usage in Swift when loading a large image as a moving background view?

I'm new to Swift and trying to learn my way through it all. One thing I can't seem to figure out is the following. I want to reduce the amount my background image uses. I successfully made a little quiz app with a moving world map in the background. But the world map is 4000 px wide & 2000 pixels high and it seems to take a lot of memory. Xcode tells me it uses 100 MB of memory, that seems way to high to me.

I managed to reduce the file size of the image already 1.7 MB, but if I go any lower it will become blurred and then it looses it purpose. Can someone guide me in the right direction to solve this issue?

Upvotes: 1

Views: 1570

Answers (1)

MirekE
MirekE

Reputation: 11555

Compressing the file won't help - the application memory contains uncompressed version. It should take approximately width * height * bit_depth * number of components. Width is 4000, height is 2000, bit depth is most likely 1 byte (8 bit) and number of components is 3 or 4 (R, G, B and possibly alpha).

You could cut your background into smaller tiles and ensure that only tiles that are displayed are in memory.

Upvotes: 2

Related Questions