应用CIFilter后,输出图像为NULL

时间:2013-09-20 06:52:24

标签: iphone ios ciimage

我想用CIImage framework对图像进行效果,当我设置参数时,输出图像显示空白图像。

有什么建议吗?

代码用于应用过滤器如下:

- (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;


}

5 个答案:

答案 0 :(得分:1)

这些是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
    )

答案 1 :(得分:0)

选中此link

并尝试使用以下代码

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

答案 2 :(得分:0)

首先,Xcode应该警告你的第一件事是你正在使用initWithImage:当你应该使用initWithCIImage :(我猜这是一个错字)。其次,您应该将self.imageView.image返回的UIImage转换为CIImage - 请参阅How to Convert UIImage to CIImage and vice versa

答案 3 :(得分:0)

问题出在这一行:

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

CIDepthOfField中没有属性(键)@“inputPoint2”。

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

使用@“inputPoint0”和@“inputPoint1”它将起作用。

要检查CIFiter属性,请使用:

[sampleFilterObject attributes]

答案 4 :(得分:0)

因为 CIDepthOfField

  

在OS X v10.6及更高版本中可用。

(c)Apple文档

在iOS设备中

过滤 CIDepthOfField NULL