简体   繁体   English

`contextWithCGContext:options:` 方法的目的是什么?

[英]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 created CIContext ?如果这个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 by CIFilters , into this initial CGContextRef ?是否可以将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 affect CIFilters 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.

相关问题 委托方法'canMoveRowAtIndexPath'的目的是什么? - What is the purpose of the delegate method 'canMoveRowAtIndexPath'? NSInvocation类上的setSelector方法的目的是什么? - What's the purpose of the setSelector method on the NSInvocation class? EAAccessoryDe​​legate中的– annexDidDisconnect:方法的目的是什么? - What is the purpose of the – accessoryDidDisconnect: method within the EAAccessoryDelegate? NSArray class 的“sortedArrayHint”方法,这个方法的目的是什么,它是如何使用的? - “sortedArrayHint” method of NSArray class, what is the purpose of this method and how is it used? 在符合NSObject的类中-self方法的目的是什么? - What is the purpose of the -self method in NSObject-conformant classes? iOS RestKit [mappingProvider setMapping:forKeyPath:]方法的用途是什么? - iOS RestKit what is the purpose of [mappingProvider setMapping:forKeyPath:] method? Objective-C中方法内部错误的目的是什么 - What is the purpose of the error inside method in Objective-C 复用标识符的目的是什么? - What is the purpose of the reuseIdentifier? 这个 Mtd 中的 purpose.parent 是什么? - What is the purpose .parent in this Mtd? UIInterfaceOrientationUnknown用于什么目的 - UIInterfaceOrientationUnknown for what purpose
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM