[英]What is the purpose of `contextWithCGContext:options:` method?
I treated CIContext
as a kind of abstract state collector, which purpose is to allow CIFilter
s to function.我将
CIContext
视为一种抽象状态收集器,其目的是让CIFilter
发挥作用。
But there is +[CIContext contextWithCGContext:options:]
function which accepts CGContextRef
as its input.但是有一个
+[CIContext contextWithCGContext:options:]
函数接受CGContextRef
作为它的输入。
What does it mean?这是什么意思? If this
CGContextRef
already contains some graphics, then how it will be used in newly created CIContext
?如果这个
CGContextRef
已经包含一些图形,那么它将如何在新创建的CIContext
中使用?
Will the contents of CGContextRef
affect CIFilters
in any way? CGContextRef
的内容会以任何方式影响CIFilters
吗?
Is it possible to output CIImages
, produced by CIFilters
, into this initial CGContextRef
?是否可以将
CIImages
生成的CIFilters
输出到这个初始CGContextRef
中?
What does it mean?
这是什么意思? If this
CGContextRef
already contains some graphics, then how it will be used in newly createdCIContext
?如果这个
CGContextRef
已经包含一些图形,那么它将如何在新创建的CIContext
中使用?
CIContext
can be backed by the CGContext
, and used to draw the filtered data on top of the context's content. CIContext
可以由CGContext
支持,并用于在上下文内容之上绘制过滤后的数据。
Is it possible to output
CIImages
, produced byCIFilters
, into this initialCGContextRef
?是否可以将
CIImages
生成的CIFilters
输出到这个初始CGContextRef
中?
(Almost) any UIView
class sets a CGContext
shortly before calling drawRect:
method, and if you are not going to produce an UIImage
/ CIImage
object, but instead just want to override this method and draw the result of your filters, you can get use of -[CIContext drawImage:inRect:fromRect:]
in order to render your (eg filtered) data to the context of this view: (几乎)任何
UIView
类都会在调用drawRect:
方法之前不久设置一个CGContext
,如果您不打算生成UIImage
/ CIImage
对象,而只是想覆盖此方法并绘制过滤器的结果,您可以使用的-[CIContext drawImage:inRect:fromRect:]
以便将您的(例如过滤后的)数据呈现到此视图的上下文中:
- (void)drawRect:(CGRect)rect {
CIContext *context = [CIContext contextWithCGContext:UIGraphicsGetCurrentContext() options:nil];
CIImage *input = self.image.CIImage;
CIFilter *filter = [[self class] makeFilter];
[filter setValue:input forKey:kCIInputImageKey];
[context drawImage:filter.outputImage
inRect:rect
fromRect:filter.outputImage.extent];
}
Will the contents of
CGContextRef
affectCIFilters
in any way?CGContextRef
的内容会以任何方式影响CIFilters
吗?
Not exactly, CIFilter
s objects in isolation don't get affected by any side effects of CGContext
state currently active.不完全是,孤立的
CIFilter
对象不会受到当前活动的CGContext
状态的任何副作用的影响。 However if the CGContext
itself has any transformation in place, it won't be discarded of course:然而,如果
CGContext
本身有任何转换,它当然不会被丢弃:
- (void)drawRect:(CGRect)rect {
CGContextRef cgContext = UIGraphicsGetCurrentContext();
CGContextRotateCTM(cgContext, radians(-45.));
CIContext *context = [CIContext contextWithCGContext:cgContext options:nil];
... Applies CIFilter sequence ...
// The result will be both filtered and rotated by 45 degrees counterclockwise
[context drawImage:filter.outputImage
inRect:rect
fromRect:filter.outputImage.extent];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.