请考虑以下代码(让我们规定imageURL是指向磁盘上JPG的有效文件URL):
CIImage *inputimage = [CIImage imageWithContentsOfURL:imageURL];CIFilter *filter = [CIFilter filterWithname:@"CIAreaAverage" keysAndValues: kCIInputimageKey,inputimage,kCIinputExtentKey,[inputimage valueForKey:@"extent"],nil];CIImage *outputimage = (CIImage *)[filter valueForKey:@"outputimage"];
运行此代码时,最后一行触发:
0 CoreFoundation 0x00007fff96c2efc6 __exceptionPreprocess + 1981 libobjc.A.dylib 0x00007fff9153cd5e objc_exception_throw + 432 CoreFoundation 0x00007fff96cbb2ae -[NSObject doesNotRecognizeSelector:] + 1903 CoreFoundation 0x00007fff96c1be73 ___forwarding___ + 3714 CoreFoundation 0x00007fff96c1bc88 _CF_forwarding_prep_0 + 2325 CoreImage 0x00007fff8f03c38d -[CIAreaAverage outputimage] + 526 Foundation 0x00007fff991d8384 _NSGetUsingkeyvalueGetter + 627 Foundation 0x00007fff991d8339 -[NSObject(NSkeyvalueCoding) valueForKey:] + 392
现在,核心图像过滤器参考清楚地指出CIAreaAverage“返回包含感兴趣区域的平均颜色的单像素图像.”实际上,当我在调试器中检查过滤器属性时(在尝试valueForKey:call之前),更令人困惑的是:
(lldb) po [filter attributes](ID) = 0x00007fb3e3ef0e00 { CIAttributeDescription = "Calculates the average color for the specifIEd area in an image,returning the result in a pixel."; CIAttributeFilterCategorIEs = ( CIcategoryReduction,CIcategoryVIDeo,CIcategoryStillimage,CIcategoryBuiltIn ); CIAttributeFilterdisplayname = "Area Average"; CIAttributeFiltername = CIAreaAverage; CIAttributeReferencedocumentation = "http://developer.apple.com/cgi-bin/apple_ref.cgi?apple_ref=//apple_ref/doc/filter/ci/CIAreaAverage"; inputExtent = { CIAttributeClass = CIVector; CIAttributeDefault = "[0 0 640 80]"; CIAttributeDescription = "A rectangle that specifIEs the subregion of the image that you want to process."; CIAttributedisplayname = Extent; CIAttributeType = CIAttributeTypeRectangle; CiuiParameterSet = CiuiSetBasic; }; inputimage = { CIAttributeClass = CIImage; CIAttributeDescription = "The image to process."; CIAttributedisplayname = Image; CiuiParameterSet = CiuiSetBasic; }; outputimage = { CIAttributeClass = CIImage; };}
那里有outputimage – 以CIImage类型给出!
那么,我做错了什么?我见过的所有文档和教程都表明-valueForKey:是访问属性的正确方法,包括outputimage.
解决方法 我相信你的范围是罪魁祸首(不管它多么奇怪).当我将范围更改为CIVector *时,它可以工作.NSURL *imageURL = [NSURL fileURLWithPath:@"/Users/davID/Desktop/vIDeo.png"];CIImage *inputimage = [CIImage imageWithContentsOfURL:imageURL];CIFilter *filter = [CIFilter filterWithname:@"CIAreaAverage"];[filter setValue:inputimage forKey:kCIInputimageKey];CGRect inputExtent = [inputimage extent];CIVector *extent = [CIVector vectorWithX:inputExtent.origin.x Y:inputExtent.origin.y Z:inputExtent.size.wIDth W:inputExtent.size.height];[filter setValue:extent forKey:kCIinputExtentKey];CIImage *outputimage = [filter valueForKey:@"outputimage"];
[inputimage extent]返回一个CGRect,但显然CIVector *效果更好.
总结以上是内存溢出为你收集整理的objective-c – 尝试访问CIFilter的outputImage时出现“无法识别的选择器”全部内容,希望文章能够帮你解决objective-c – 尝试访问CIFilter的outputImage时出现“无法识别的选择器”所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)