Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What consumes less memory an actual image or a drawn image?

I am designing an app and I am creating some images with PaintCode.

Using that program I get the actual code for each image that I create, thus allowing me to choose to insert code or use an actual image. I was wondering what would consume less memory, the image code or an actual PNG?

I know an image memory consumption is width x height x 4 = bytes in memory but I have no idea whether an image that is generated by code is more memory efficient, less memory efficient or breaks even?

This decision is particularly important given the different screen resolutions. its a lot easier to create an image in code and expand it to whatever size I want rather than go to Photoshop every time.

like image 558
Jonathan Thurft Avatar asked May 13 '13 12:05

Jonathan Thurft


1 Answers

This answer varies from other answers because I have the impression the graphics context is your most common destination -- that you are not always rendering to a discrete bitmap. So for the purposes of typical drawing:

I was wondering what would consume less memory, the image code or an actual PNG?

It's most likely that the code will result in far less memory consumption.

I have no idea whether an image that is generated by code is more memory efficient, less memory efficient or breaks even?

There are a lot of variables and there is no simple equation to tell you which is better for any given input. If it's simple enough to create with a WYSIWYG, it's likely much smaller as code.

If you need to create intermediate rasterizations or layers for a vector based renderer, then memory will be about equal once you have added the first layer. Typically, one does/should not render each view or layer (not CALayer, btw) to these intermediates and instead render directly into the graphics context. When all your views render directly into the graphics context, they write to the same destination.

With code, you also open yourself to a few other variables which have the potential to add a lot of memory. The effects of font loading and caching can be quite high, and the code generator you use is not going to examine how you could achieve the best caching and sharing of these resources if you find you need to minimize memory consumption.

like image 79
justin Avatar answered Oct 29 '22 04:10

justin