首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在ios中对uiimage应用滤镜来去除阴影和灯光?

如何在ios中对uiimage应用滤镜来去除阴影和灯光?
EN

Stack Overflow用户
提问于 2015-06-15 18:53:13
回答 2查看 1.3K关注 0票数 1

我想在ios中应用滤镜uiimage来去除阴影和灯光。我有下面的android代码。我需要在ios中使用它的等价物。

代码语言:javascript
复制
public static Bitmap changeBitmapContrastBrightness(Bitmap bmp, float contrast, float brightness)
{
ColorMatrix cm = new ColorMatrix(new float[]
        {
            contrast, 0, 0, 0, brightness,
            0, contrast, 0, 0, brightness,
            0, 0, contrast, 0, brightness,
            0, 0, 0, 1, 0
        });

Bitmap ret = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), bmp.getConfig());

Canvas canvas = new Canvas(ret);

Paint paint = new Paint();
paint.setColorFilter(new ColorMatrixColorFilter(cm));
canvas.drawBitmap(bmp, 0, 0, paint);

return ret;
}

我已经使用了下面的ios代码,但无法获得正确的结果

代码语言:javascript
复制
CIImage *inputImage = [CIImage imageWithCGImage:[UIImage   imageNamed:@"facedetectionpic.jpg"].CGImage]; // 1
// Make the filter
CIFilter *colorMatrixFilter = [CIFilter filterWithName:@"CIColorMatrix"]; // 2
[colorMatrixFilter setDefaults]; // 3
[colorMatrixFilter setValue:inputImage forKey:kCIInputImageKey]; // 4
[colorMatrixFilter setValue:[CIVector vectorWithX:1 Y:1 Z:1 W:0] forKey:@"inputRVector"]; // 5
[colorMatrixFilter setValue:[CIVector vectorWithX:0 Y:1 Z:0 W:0] forKey:@"inputGVector"]; // 6
[colorMatrixFilter setValue:[CIVector vectorWithX:0 Y:0 Z:1 W:0] forKey:@"inputBVector"]; // 7
[colorMatrixFilter setValue:[CIVector vectorWithX:0 Y:0 Z:0 W:1] forKey:@"inputAVector"]; // 8

// Get the output image recipe
CIImage *outputImage = [colorMatrixFilter outputImage];  // 9

// Create the context and instruct CoreImage to draw the output image recipe into a CGImage
CIContext *context = [CIContext contextWithOptions:nil];
CGImageRef cgimg = [context createCGImage:outputImage fromRect:[outputImage extent]]; // 10
EN

回答 2

Stack Overflow用户

发布于 2015-06-15 19:04:44

代码语言:javascript
复制
    -(void)fiterImage:(CIColor*)imgFirstColor:(CIColor*)imgSecondColor:(CIColor*)imgThirdColor:(CIColor*)imgForthColor
        {
            CIImage *rawImageData1;
//arrImagesTemp image array
            rawImageData1 =[[CIImage alloc] initWithImage:[arrImagesTemp objectAtIndex:0]];

            if (rawImageData1)
            {
                CIImage* outputImage = nil;

                CIFilter* greenGenerator = [CIFilter filterWithName:@"CIConstantColorGenerator"];

                [greenGenerator setValue:imgFirstColor forKey:@"inputColor"];
                CIImage* greenImage = [greenGenerator valueForKey:@"outputImage"];

                CIImage *rawImageData =[[CIImage alloc] initWithImage:[arrImagesTemp objectAtIndex:0]];
                CIFilter* filter = [CIFilter filterWithName:@"CIMultiplyCompositing"];
                [filter setValue:greenImage forKey:@"inputImage"];
                [filter setValue:rawImageData forKey:@"inputBackgroundImage"];
                outputImage = [filter valueForKey:@"outputImage"];

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

                CIContext* context = [CIContext contextWithOptions:nil];
                CGImageRef outputImageRef = [context createCGImage:filteredImageData fromRect:[filteredImageData extent]];
                UIImage *modifiedPhoto = [UIImage imageWithCGImage:outputImageRef scale:1 orientation:UIImageOrientationUp];

            }
        }
票数 0
EN

Stack Overflow用户

发布于 2015-06-15 19:06:22

这是用于数据过滤的.this逻辑,在代码中用作图像过滤remove shadow或brightness

代码语言:javascript
复制
  if ([categoryTitle isEqualToString:@"Category"])
         {
             isCategory=NO;
         }
         else
         {

         categoryData=[[NSMutableArray alloc]init];
         for (int a=0; a<fetchedDataArray.count; a++)
         {
             categoryDictionary=[[NSMutableDictionary alloc]init];
             categoryDictionary=[fetchedDataArray objectAtIndex:a];
             NSString *categ=[[[[[categoryDictionary objectForKey:@"terms"] objectForKey:@"offershop"] objectAtIndex:0] objectForKey:@"parent"] objectForKey:@"name"];
             if ([categoryTitle isEqualToString:categ])
             {
                 [categoryData addObject:categoryDictionary];
             }
             //searchDictionary=nil;
         }
         NSLog(@"done");
         }
         [self.tableview reloadData];

     }
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30843355

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档