iOS - 这是放置图像的更好选择吗?核心图形(PaintCode应用程序)vs图像文件(png) [英] iOS - which is the better option to put images? Core Graphics(PaintCode App) vs Image files(png)

查看:142
本文介绍了iOS - 这是放置图像的更好选择吗?核心图形(PaintCode应用程序)vs图像文件(png)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款使用相当多图片的iOS应用。我对如何在应用程序中加载图像感到困惑。大约5年前,人们提出了类似问题。但从那时起,情况发生了很大变化。所以我想,开始一个新线程会更有意义。

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.

我认为我有两种选择:


  1. 使用PaintCode应用程序(你可以在这里找到它)为您提供CG代码以在运行时绘制图像。

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

放入.png图像文件(1x,2x,3x)

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.

我主要担心的是:


  1. 在运行时绘制图像是否会影响性能和其他关键参数。

  2. 在什么情况下,png文件会更合适。

所以,我在这里,寻求更多知识渊博的人的意见。
提前致谢。

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

推荐答案

如果图纸很简单 - 请使用Core Graphics。



你对所有支持Core Graphics / PaintCode方法的观点都是正确的。

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.

如你所说,它是未来证明,比导入资产更灵活。


  • 您想要更改该自定义按钮的颜色?在您的函数中输入一个不同的参数,而不是为每个分辨率重新制作3个图像。

  • You want to change the color of that custom button? Input a different argument into your function, instead of re-making 3 images for each resolution.

您想要缩放该绘图吗?只需重新绘制一个新尺寸。

You want to scale that drawing up? Just re-draw it with a new size.

新款iPhone 8s在不久的将来会有4倍显示器问世吗?您的应用已经可以处理它。

The new iPhone 8s comes out sometime in the near future with a 4x display? Your app can already handle it.

正如您所说,它会减少您的应用包的大小,这太棒了。


  • 用户下载量减少,而且对您的尺寸优化担忧减少。

绘图核心图形是100%在CPU上完成的,因此如果您做了大量的工作,它将影响性能。主线程上的复杂图纸。

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.

作为 Tricertops说,复杂CG绘图的一个主要例子是具有大半径的阴影。另一个例子是在你的上下文中使用复杂的路径。

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!


  • 您可以在后台线程 上进行离线绘制,然后将绘制的图像传递到主屏幕上线程(您必须从主线程进行UI更新),但这仍然会导致一些延迟问题(图像只是出现在屏幕上)。但是,这可能是加载复杂图纸的好方法,您将在应用的后期使用它。

  • You can do drawing off-screen on a background thread, and then pass the drawn image to the screen on the main thread (you must do UI updates from the main thread), but this will still cause some latency problems (images just appearing on the screen from nowhere). However, this can be a good way of loading in complex drawings that you're going to be using at a later stage of the app.

您还可以通过在加载应用时加载Core Graphics图像来牺牲一些应用启动时间,但这可能对用户不利,具体取决于您需要绘制的图像的复杂程度和数量。

You could also sacrifice some app launch time by loading in your Core Graphics images when the app loads, but this may be undesirable for the user, depending on the complexity and number of images you need to draw.

您可以通过保留经常绘制的图像缓存(按钮背景等)来重复使用图纸。这样可以提高性能牺牲了一点RAM。 PaintCode实际上在您使用非参数化的StyleKits时自动执行此操作

You can re-use drawings by keeping a cache of images that you're drawing frequently (button backgrounds etc.) This will improve performance by sacrificing a little bit of RAM. PaintCode actually automatically does this when you use non-parameterised StyleKits.

虽然看到iOS硬件要比它快得多当问到这个问题时,绘制Core Graphics代码的实际CPU使用率比以前少得多,因此您现在可以在更快的设备上使用更复杂的绘图。

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.

但是,您可能会发现某些复杂的图形根本不可能,或者将永远在Core Graphics中创建。在这种情况下,我肯定建议使用图像。

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.

如果您发现自己花费数周时间尝试在Core Graphics中创建绘图,那么您可能会感觉更好只是使用图像并更有效地花费时间!

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!

尽管,只要你保持你的绘图简单,并重新尽可能使用图纸,使用Core Graphics时不必担心性能问题。

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.

在我看来,使用Core Graphics / PaintCode的优点很简单只要使用得当,图纸就会超过缺点。

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

这篇关于iOS - 这是放置图像的更好选择吗?核心图形(PaintCode应用程序)vs图像文件(png)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆