创建其中包含图像的 CALayer 最有效的方法是什么?
我想知道最有效的方法是制作一个带有图像的 CALayer。
我知道你可以加载 UIImage 然后调用 [image CGImage] 但这是最好的方法吗? 据我从苹果的文档中可以看出,这是唯一的方法。
I am wondering what the most efficient way is to make a CALayer with an image in it.
I know you can load a UIImage and then call [image CGImage] but is this the best way of going about it? As far as I can tell from Apple's documentation this is the only way you can do it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
HTH
Try this:
HTH
好吧,
CGImage
不是CALayer
,所以你显然留下了一些步骤,但我假设你知道你在说什么,就绘图而言到CALayer
或其他什么。如果您的问题是关于在不使用 UIImage 的情况下创建 CGImage 的问题,您可以尝试查看以下函数:
如果您事先知道它是什么类型的图像,则只需使用适当的方法即可。 否则,您需要查看文件签名以查看它是否包含 PNG 或 JFIF。 当然,这需要您实现一个
CGDataProvider
。我认为这正是 UIImage 类已经在做的事情。 如果您想从中充分发挥效率,可以在
UIImage
类中使用以下方法之一:这些方法之间的唯一区别
是
imageNamed:
缓存图像。 如果您使用第一种方法,则不会。Well, a
CGImage
isn't aCALayer
, so you are obviously leaving some steps out there, but I assume you know what you're talking about, as far as drawing to aCALayer
or whatnot.If your question is about creating
CGImage
s without using a UIImage, you can try looking into the following functions:If you happen to know beforehand what sort of image it is, just use the appropriate method. Otherwise, you'd need to look at the file signature to see if it contains PNG or JFIF. Of course, this requires you implement a
CGDataProvider
.I assume this is exactly what the
UIImage
class is already doing. If you want to squeeze out every bit of efficiency from that, you can use one of the following methods in theUIImage
class:The only difference between these methods and
is that
imageNamed:
caches the image. If you use one of the first methods, it does not.