iosperformancecore-graphicsresolutionpaintcode

iOS - which is the better option to put images? Core Graphics(PaintCode App) vs Image files(png)


I am developing an iOS app which uses quite a few images. I am kind of confused about how to load the images in the app. A similar question was asked around 5 years ago. But a lot has changed since then. So I thought, it would make more sense to start a new thread.

There are mainly two options that I think I have:

  1. Use PaintCode app (you can find it here) which gives you CG code to draw images at the runtime.

  2. Put .png image files (1x, 2x, 3x)

The things like about the first option are:

• The first most important and unbeatable feature: Draw dynamic images i.e. to be able to change the content and gives basic animation effects using variables and equations

• The second most important thing: parametric images that behaves perfectly when frame changes no stretching or distortion

• Less size - As we not gonna use image files, reduces the overall size of the app drastically (top concern these days). E.g. PaintCode App in itself weights only ~5 MB (leaving out icon files).

• Resolution independence

• Very easy to use. Especially you don't need to remember names. You simply make some function calls.

My major concerns are:

  1. Does drawing images at the runtime affects performance and other critical parameters.
  2. Under what circumstances, the png files would be a better fit.

So, here I am, seeking opinions from more knowledgable people. Thanks in advance.


Solution

  • If the drawing is simple - use Core Graphics.

    You are correct on all the points you make in favour of the Core Graphics/PaintCode approach.

    As you say, It's future proof and so much more flexible than importing assets.

    As you also say, it decreases the size of your app bundle, which is amazing.


    However.

    Drawing with Core Graphics is 100% done on the CPU, so it will affect performance if you do numerous & complex drawings on the main thread.

    As Tricertops says, a prime example of a complex CG drawing is shadows with large radii. Another example is using complicated paths in your context.

    Do not despair though, there are ways to combat this!

    Although, seeing as iOS hardware is much quicker than what it was when this question was asked, the actual CPU usage that drawing Core Graphics code is much less than it used to be, so you can now get away with more complicated drawings on faster devices.

    However, you may find that some complex drawings are simply impossible or would take forever to create in Core Graphics. In this case, I would definitely recommend using images.

    As the answerer very eloquently put on the post you linked to:

    The fastest program is the one that reaches the market first.

    If you're finding yourself spending weeks trying to create a drawing in Core Graphics, you're probably better off just using images and spending that time more productively!


    Although, as long as you keep your drawing simple, and re-use drawings wherever you can, you shouldn't have to worry about performance issues with using Core Graphics.

    In my opinion, the pros of using Core Graphics/PaintCode for simple drawings far outweighs the drawbacks, so long as it is used properly.