欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

iOS-UIImage图片绘制颜色

程序员文章站 2022-09-07 13:05:54
- (UIImage *)dtk_setImageColor:(UIColor *)imageColor{ //获取画布 UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0f); //画笔沾取颜色 [imageColor setFill... ......
- (uiimage *)dtk_setimagecolor:(uicolor *)imagecolor{
    //获取画布
    uigraphicsbeginimagecontextwithoptions(self.size, no, 0.0f);
    //画笔沾取颜色
    [imagecolor setfill];
    cgrect bounds = cgrectmake(0, 0, self.size.width, self.size.height);
    //绘制一次
    uirectfill(bounds);
    //再绘制一次
    [self drawinrect:bounds blendmode:kcgblendmodeoverlay alpha:1.0f];
    //获取图片
    [self drawinrect:bounds blendmode:kcgblendmodedestinationin alpha:1.0f];
    uiimage *image = uigraphicsgetimagefromcurrentimagecontext();
    uigraphicsendimagecontext();
    return image;
}