ios - Mask an image and fill with color -
i mask image color , filling both selection , rest. i'm using cgimagecreatewithmaskingcolors, don't know how fill image color.
here begining of code
uiimage *source = [uiimage imagenamed:@"nb.png"]; const cgfloat mymaskingcolors[6] = {0,110,0,110,0,110}; cgimageref imageref = cgimagecreatewithmaskingcolors(source.cgimage, mymaskingcolors); uiimage* imageb = [uiimage imagewithcgimage:imageref]; uiimageview *imageview = [[uiimageview alloc]initwithimage:imageb]; thanks edit: think not clear, 1 color selection , color rest
if want 2 colors applied on image can apply gradient on image this
- (uiimage *)applygradientonimage:(uiimage *)image withstartcolor:(uicolor *)color1 endcolor:(uicolor *)color2 { uigraphicsbeginimagecontextwithoptions(image.size, no, image.scale); cgcontextref context = uigraphicsgetcurrentcontext(); cgcontexttranslatectm(context, 0, image.size.height); cgcontextscalectm(context, 1.0, -1.0); cgcontextsetblendmode(context, kcgblendmodenormal); cgrect rect = cgrectmake(0, 0, image.size.width, image.size.height); //cgcontextdrawimage(context, rect, img.cgimage); // create gradient nsarray *colors = [nsarray arraywithobjects:(id)color2.cgcolor, (id)color1.cgcolor, nil]; cgcolorspaceref space = cgcolorspacecreatedevicergb(); cggradientref gradient = cggradientcreatewithcolors(space, (__bridge cfarrayref)colors, null); // apply gradient cgcontextcliptomask(context, rect, image.cgimage); cgcontextdrawlineargradient(context, gradient, cgpointmake(0,0), cgpointmake(0, image.size.height), 0); uiimage *gradientimage = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); cggradientrelease(gradient); cgcolorspacerelease(space); return gradientimage; }
Comments
Post a Comment