【问题标题】:Getting an alpha channel when using CIFilters [How to clear it]使用 CIFilters 时获取 alpha 通道 [如何清除它]
【发布时间】:2012-11-17 01:07:18
【问题描述】:

在 UIImage 上应用锐化滤镜时遇到了一点问题。

代码完美运行,但生成的 UIImage 具有 Alpha 通道的问题。这反过来会导致一些性能问题。

这就是我初始化上下文和过滤器的方式

EAGLContext *myEAGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
 NSMutableDictionary *options = [[NSMutableDictionary alloc] init];
[options setObject: [NSNull null] forKey: kCIContextWorkingColorSpace];
context = [CIContext contextWithEAGLContext:myEAGLContext options:options];
sharpenLuminanceFilter = [CIFilter filterWithName:@"CISharpenLuminance"];

我使用下面的函数来生成一张图片

- (UIImage *)applySharpingFilter:(UIImage *)originalImage withValue:(float)value{

CIImage *image = [CIImage imageWithCGImage:originalImage.CGImage];
[sharpenLuminanceFilter setValue:image forKey:@"inputImage"];
[sharpenLuminanceFilter setValue:[NSNumber numberWithFloat:value] forKey:@"inputSharpness"];
CIImage * result = sharpenLuminanceFilter.outputImage;
CGImageRef cgimg = [context createCGImage:result fromRect:[result extent]];
 double scaleFactor = [UIScreen mainScreen].scale;
UIImage *finalImage = [UIImage imageWithCGImage:cgimg scale:scaleFactor orientation:UIImageOrientationUp];
CGImageRelease(cgimg);
[sharpenLuminanceFilter setValue:nil forKey:@"inputImage"];
return finalImage;

}

无论如何我可以指定我希望生成的图像是不透明的并且没有 alpha 通道吗?

【问题讨论】:

    标签: cocoa-touch uiimage core-graphics core-image cifilter


    【解决方案1】:

    您可以使用CIColorMatrix 过滤器。将矩阵设置为恒等式,将偏差设置为 [0, 0, 0, 1],它应该在 alpha 上加 1,这将使它成为实心的。

    我很想知道 Alpha 通道以何种方式影响您的表现。

    【讨论】:

    • 这只是让整个画面更白,并没有消除阿尔法通道。如果您有透明的图像,该问题会影响滚动时的性能
    • 您的频道订单不是 RGBA 吗?如果是这样,您可能需要更改偏置向量,使 1 与您的 Alpha 通道处于相同位置。
    • 我尝试了所有组合,结果图像始终具有 Alpha 通道。有没有办法在创建 CGImage 时去掉 alpha 通道?
    • 我想你可以创建一个没有 alpha 通道的新 CGBitmapContext 并调用 CGContextDrawImage() 在那里绘制它。
    猜你喜欢
    • 1970-01-01
    • 2021-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-24
    • 1970-01-01
    • 1970-01-01
    • 2012-08-31
    相关资源
    最近更新 更多