Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 向图像添加色调_Objective C_Ios_Uiimageview_Uiimagepickercontroller - Fatal编程技术网

Objective c 向图像添加色调

Objective c 向图像添加色调,objective-c,ios,uiimageview,uiimagepickercontroller,Objective C,Ios,Uiimageview,Uiimagepickercontroller,我正在创建一个应用程序,它使用UIImagePickerController向用户展示一个相机,并在相机“视图”上覆盖两个网格/图案中的一个 网格本身是添加到覆盖中的UIImageView中的.png文件,它们非常复杂,因此我真的希望避免用代码绘制网格,尽管这会为我的问题提供一个干净简单的答案 我想能够提供各种颜色的网格。显而易见的解决方案是创建更多不同颜色的.png图像,但对于每种颜色,必须有四个单独的图像(每个网格的规则图像和视网膜图像),这样可以快速增加大量资产 我认为最理想的解决方案是,

我正在创建一个应用程序,它使用
UIImagePickerController
向用户展示一个相机,并在相机“视图”上覆盖两个网格/图案中的一个

网格本身是添加到覆盖中的
UIImageView
中的.png文件,它们非常复杂,因此我真的希望避免用代码绘制网格,尽管这会为我的问题提供一个干净简单的答案

我想能够提供各种颜色的网格。显而易见的解决方案是创建更多不同颜色的.png图像,但对于每种颜色,必须有四个单独的图像(每个网格的规则图像和视网膜图像),这样可以快速增加大量资产

我认为最理想的解决方案是,我只需创建白色/灰色的网格,然后对其进行着色,使其具有适当的颜色


可能吗?还是我需要寻找另一种解决方案?

感谢Ananth给我指点

我已按照问题中的建议将此方法添加到代码中,并对willc2的答案进行了修改:

-(UIImage *)colorizeImage:(UIImage *)baseImage color:(UIColor *)theColor {
    UIGraphicsBeginImageContext(baseImage.size);

    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGRect area = CGRectMake(0, 0, baseImage.size.width, baseImage.size.height);

    CGContextScaleCTM(ctx, 1, -1);
    CGContextTranslateCTM(ctx, 0, -area.size.height);
    CGContextSaveGState(ctx);
    CGContextClipToMask(ctx, area, baseImage.CGImage);
    [theColor set];
    CGContextFillRect(ctx, area);
    CGContextRestoreGState(ctx);
    CGContextSetBlendMode(ctx, kCGBlendModeMultiply);
    CGContextDrawImage(ctx, area, baseImage.CGImage);
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}

…我得到的正是我想要的。

看这里:你检查过[这篇文章][1]了吗?它似乎更接近你所需要的。[1] :不要用这个。这会降低图像质量。使用此选项,不会造成质量损失: