0

我想用 对图像产生影响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;


}
4

5 回答 5

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
    )
于 2013-09-20T10:22:15.227 回答
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]
于 2014-03-09T13:29:15.060 回答
0

无论如何,Xcode 应该警告你的第一件事是你正在使用 initWithImage: 当你应该使用 initWithCIImage: 时(我猜这是一个错字)。其次,您应该将 self.imageView.image 返回的 UIImage 转换为 CIImage - 请参阅如何将 UIImage 转换为 CIImage,反之亦然

于 2013-12-13T11:52:22.660 回答
0

检查此链接

并尝试使用以下代码

  CIImage *filteredImage = [invertColour outputImage];
  UIImage *newImg = [UIImage imageWithCIImage:filteredImage];
于 2013-09-20T07:09:45.080 回答
0

因为CIDepthOfField

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

(c) 苹果文件

iOS 设备中的过滤器CIDepthOfFieldNULL

于 2014-11-19T14:56:48.510 回答