ios - How to determine the number of bytes used by a UIImage? -


i able calculate total number of bytes uiimage uses in memory.

i can make rough estimate multiplying width height , multiplier number of bytes, i'd calculate size if possible.

in general, objects don't have single meaningful "size", since can allocate , release number of other objects privately needed. sizeof(*myobj) gives size of top level structure, not useful number. if need complete memory impact of allocating , using object, run under instruments , watch allocations.

for uiimage, practical size size of whatever backing it, typically either nsdata containing png, or cgimageref, plus object overhead. (there's pixel buffer when gets rendered screen or other context; buffer belongs view or context in question, not uiimage. if uiview doing rendering buffer in gl texture memory anyway.)

[uiimage imagewithdata:[nsdata datawithcontentsoffile:@"foo.png"]] gives uiimage same size foo.png file, plus inconsequential overhead. [uiimage imagenamed:@"foo.png"] same thing, except class maintains cache table of 1 object per filename, , cause object dump memory copy of png in low-memory situations, reducing "size" overhead.

imagewithcgimage: , variants give uiimage uses cgimage reference backing store, , cgimages can number of things depending on source. if you've been painting in one, it's uncompressed pixel buffer. calculate size propose above. if need size "would be" if file, inspect result of uiimagepngrepresentation or uiimagejpegrepresentation functions.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -