12/28/2023 0 Comments Thinkin things 1 iosHowever, it’ll actually hang onto it as well. This paints a clear picture of why the dimensions are so important when it comes to your memory consumption when working with images.įor UIImage in particular, when we give it image data we received from a network hit or some other source, it decodes that data buffer to whatever compression the data says it’s encoded in (think PNG or JPEG). So it stands to reason that this size is intrinsically tied to the proportions of the image itself and not its file size. Here, iOS has created a buffer - specifically an image buffer, that’s got an in-memory representation of the image. Even if it’s just by a 60 by 60 point image view. It’s now uncompressed, and it’s here we’re at the 14MB size listed above.ģ) Render - Just like it sounds, the image data is ready and willing to be rendered any which way. Really no worries yet.Ģ) Decode - Now, iOS takes the image and converts into a way the GPU can read and understand. When you load up an image, it’s going to be processed in three steps:ġ) Load - iOS takes the compressed image and loads (in our example) the 266 kilobyte into memory. The Rendering PipelineĪll that to say - it’s worth knowing what’s going on under the hood. If each one is a conservative 256x256 you could still be taking quite a hit on memory. If you’re thinking things are kosher because each one has been packed up nice and tight from ImageOptim or something similar, that might not be the case. Imagine if you’ve got a table view with a list of users, and each row shows the now pervasive circle avatar of their photo to the left. Assuming each pixel will cost us four bytes:ġ718 * 2048 * 4 / 1024 / 1024 = 13.42 megabytes give or take And the dimensions for this photo sit at 1718 pixels wide by 2048 pixels tall. IOS essentially derives its memory hit from an image’s dimensions - whereas the actual file size has much less to do with it. Pop quiz - how much memory will this 266 kilobyte (and quite dashing) photo of my beautiful daughter require in an iOS app? With a little know how as to what’s happening in UIKit and why in regards to how it treats images, one can gain some massive savings and forgo the unrelenting wrath of jetsam. On a vacation? It didn’t happen if it’s not documented on your Instagram story with several candid shots.īreaking news? Check Twitter and see what outlets are reporting on by peeping their photos of an event unfolding in real time.īut for all of their ubiquity on the platform, the act of showing them in a performant and memory conservative manner can easily turn into a mismanaged endeavor. If that adage holds any weight, then without question - stem to stern the iPhone is the most important camera on the planet. They say the best camera is the one you have with you.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |