iOS上的UIGraphicsBeginImageContext与CGBitmapContextCreate [英] UIGraphicsBeginImageContext vs CGBitmapContextCreate on iOS

查看:153
本文介绍了iOS上的UIGraphicsBeginImageContext与CGBitmapContextCreate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个非常愚蠢的问题,但有人可以告诉我使用UIGraphicsBeginImageContext创建CGContextRef和使用CGBitmapContextCreate绘制图像之间的区别吗?特别是现在因为UIKit绘图是线程安全的,我想知道是否有任何理由使用CGBitmapContextCreate而不是UIGraphicsBeginImageContext。

This may be a really stupid question, but can someone tell me the difference between creating a CGContextRef using UIGraphicsBeginImageContext and using CGBitmapContextCreate for drawing to images? Especially now since UIKit drawing is thread safe I was wondering if there was any reason to use CGBitmapContextCreate over UIGraphicsBeginImageContext.

推荐答案

根据Apple的说法 UIKit功能参考,其中包含封面日期2010年11月15日, UIGraphicsBeginImageContext 和相关函数仍应仅在主线程上调用。在最新的Xcode 3.2.5附带的开发人员文档中重复了相同的文本。但是,它为 UIGraphicsGetCurrentContext 报告了相同的内容,我现在明确地将其理解为线程安全。我的理解是只有 UIGraphicsGetCurrentContext 和UIImage,UIColor和UIFont类现在是线程安全的而不是整个UIKit,但我无法找到明确的引用。

According to Apple's UIKit Function Reference, which carries the cover date of the 15th November 2010, UIGraphicsBeginImageContext and related functions should still be called on the main thread only. The same text is repeated in the developer documentation that comes with the latest Xcode, 3.2.5. However, it reports the same for UIGraphicsGetCurrentContext which I explicitly understood to be thread safe now. My understanding was that only UIGraphicsGetCurrentContext and the UIImage, UIColor and UIFont classes are now thread safe rather than the entirety of UIKit, but I'm unable to find a definitive reference.

无论如何, UIGraphicsBeginImageContext 是一个位于 CGBitmapContextCreate 并减少其功能。特别是,您只能使用具有固定组件顺序的RGBA色彩空间图像(尽管它根据iOS版本而有所不同),并且无法指定您自己的绘图目标缓冲区。因此,例如,对于做一堆CoreGraphics组合然后将结果发布到OpenGL并且没有用于将已经以某种数组形式输入到CoreGraphics中的图形无用而无用。

Regardless, UIGraphicsBeginImageContext is a UIKit wrapper that sits on top of CGBitmapContextCreate and reduces its functionality. In particular you're limited to RGBA colour space images with a fixed component order (though it varies according to the iOS version) and cannot specify your own target buffer for drawing. So, for example, it's useless for doing a bunch of CoreGraphics composition and then posting the result off to OpenGL and unhelpful for piping graphics you've already got in some array form into CoreGraphics.

但是,在UIKit方法支持您需要的功能并且使用安全的地方,CoreGraphics方法没有固有的优势。

However, where the UIKit method supports the functionality you need and is safe to use, there is no inherent advantage to the CoreGraphics methods.

这篇关于iOS上的UIGraphicsBeginImageContext与CGBitmapContextCreate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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