简体   繁体   English

应用CIFilter后,输出图像给出NULL

[英]Output Image gives NULL after applying CIFilter

I want to give effects on the image with CIImage framework , and when i set parameters for that the out put image shows blank image. 我想使用CIImage framework对图像进行处理,当我为此设置参数时,输出图像显示空白图像。

Any suggestions? 有什么建议么?

Code is used to apply filter is as follows : 用于应用过滤器的代码如下:

- (IBAction)filterImage:(id)sender {

    CIImage *rawImageData;
    rawImageData =[[CIImage alloc] initWithImage:self.imageView.image];

    CIFilter *filter = [CIFilter filterWithName:@"CIDepthOfField"];
    [filter setDefaults];

    [filter setValue:rawImageData forKey:@"inputImage"];

    [filter setValue:[CIVector vectorWithCGPoint:CGPointMake(50, 50)]
              forKey:@"inputPoint1"];

    [filter setValue:[CIVector vectorWithCGPoint:CGPointMake(100, 100)]
              forKey:@"inputPoint2"];

    [filter setValue:[NSNumber numberWithFloat:15.00]
              forKey:@"inputSaturation"];    

    [filter setValue:[NSNumber numberWithFloat:15.00]
              forKey:@"inputUnsharpMaskRadius"];

    [filter setValue:[NSNumber numberWithFloat:15.70]
              forKey:@"inputRadius"];



    CIImage *filteredImageData = [filter valueForKey:@"outputImage"];

    UIImage *filteredImage = [UIImage imageWithCIImage:filteredImageData];
    self.imageView.image = filteredImage;


}

These are available iOS filters, we can use 这些是可用的iOS过滤器,我们可以使用

NSArray *filterNamesArray = [CIFilter filterNamesInCategories:[NSArray arrayWithObject:kCICategoryBuiltIn]];

  $1 = 0x071b8560 <__NSArrayI 0x71b8560>(
    CIAdditionCompositing,
    CIAffineClamp,
    CIAffineTile,
    CIAffineTransform,
    CIBarsSwipeTransition,
    CIBlendWithMask,
    CIBloom,
    CIBumpDistortion,
    CIBumpDistortionLinear,
    CICheckerboardGenerator,
    CICircleSplashDistortion,
    CICircularScreen,
    CIColorBlendMode,
    CIColorBurnBlendMode,
    CIColorControls,
    CIColorCube,
    CIColorDodgeBlendMode,
    CIColorInvert,
    CIColorMap,
    CIColorMatrix,
    CIColorMonochrome,
    CIColorPosterize,
    CIConstantColorGenerator,
    CICopyMachineTransition,
    CICrop,
    CIDarkenBlendMode,
    CIDifferenceBlendMode,
    CIDisintegrateWithMaskTransition,
    CIDissolveTransition,
    CIDotScreen,
    CIEightfoldReflectedTile,
    CIExclusionBlendMode,
    CIExposureAdjust,
    CIFalseColor,
    CIFlashTransition,
    CIFourfoldReflectedTile,
    CIFourfoldRotatedTile,
    CIFourfoldTranslatedTile,
    CIGammaAdjust,
    CIGaussianBlur,
    CIGaussianGradient,
    CIGlideReflectedTile,
    CIGloom,
    CIHardLightBlendMode,
    CIHatchedScreen,
    CIHighlightShadowAdjust,
    CIHoleDistortion,
    CIHueAdjust,
    CIHueBlendMode,
    CILanczosScaleTransform,
    CILightenBlendMode,
    CILightTunnel,
    CILinearGradient,
    CILineScreen,
    CILuminosityBlendMode,
    CIMaskToAlpha,
    CIMaximumComponent,
    CIMaximumCompositing,
    CIMinimumComponent,
    CIMinimumCompositing,
    CIModTransition,
    CIMultiplyBlendMode,
    CIMultiplyCompositing,
    CIOverlayBlendMode,
    CIPinchDistortion,
    CIPixellate,
    CIRadialGradient,
    CIRandomGenerator,
    CISaturationBlendMode,
    CIScreenBlendMode,
    CISepiaTone,
    CISharpenLuminance,
    CISixfoldReflectedTile,
    CISixfoldRotatedTile,
    CISmoothLinearGradient,
    CISoftLightBlendMode,
    CISourceAtopCompositing,
    CISourceInCompositing,
    CISourceOutCompositing,
    CISourceOverCompositing,
    CIStarShineGenerator,
    CIStraightenFilter,
    CIStripesGenerator,
    CISwipeTransition,
    CITemperatureAndTint,
    CIToneCurve,
    CITriangleKaleidoscope,
    CITwelvefoldReflectedTile,
    CITwirlDistortion,
    CIUnsharpMask,
    CIVibrance,
    CIVignette,
    CIVortexDistortion,
    CIWhitePointAdjust
    )

Check this link 检查此链接

and try using the following code 并尝试使用以下代码

  CIImage *filteredImage = [invertColour outputImage];
  UIImage *newImg = [UIImage imageWithCIImage:filteredImage];

The first thing, which Xcode should warn you about anyway, is that you are using initWithImage: when you should be using initWithCIImage: (I'm guessing that's a typo). Xcode应该警告您的第一件事是,您正在使用initWithImage:;当您应使用initWithCIImage:时(我猜这是一个错字)。 Second you should be converting the UIImage returned by self.imageView.image into a CIImage - see How to Convert UIImage to CIImage and vice versa 其次,您应该将self.imageView.image返回的UIImage转换为CIImage-请参阅如何将UIImage转换为CIImage,反之亦然

The problem is in this line: 问题在这一行:

[filter setValue:[CIVector vectorWithCGPoint:CGPointMake(100, 100)]
          forKey:@"inputPoint2"];

There is no attribute (key) @"inputPoint2" in CIDepthOfField. CIDepthOfField中没有属性(键)@“ inputPoint2”。

Documentation: https://developer.apple.com/library/mac/documentation/graphicsimaging/reference/CoreImageFilterReference/Reference/reference.html#//apple_ref/doc/filter/ci/CIDepthOfField is wrong. 文档: https : //developer.apple.com/library/mac/documentation/graphicsimaging/reference/CoreImageFilterReference/Reference/reference.html#//apple_ref/doc/filter/ci/CIDepthOfField错误。

Use @"inputPoint0" and @"inputPoint1" and it will work. 使用@“ inputPoint0”和@“ inputPoint1”,它将起作用。

To inspect CIFiter attributes use: 要检查CIFiter属性,请使用:

[sampleFilterObject attributes]

Because CIDepthOfField 因为CIDepthOfField

Available in OS X v10.6 and later. 在OS X v10.6和更高版本中可用。

(c) Apple documentation (c)Apple文档

Filter CIDepthOfField is NULL in iOS device 在iOS设备中,过滤器CIDepthOfFieldNULL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM