uiimage - Invert colors of image with transparent background -


i have uiimage transparent background. if invert colors follow method, transparent background change white , black.

i want doesnt invert transparent pixels? how can that?

-(uiimage *) getimagewithinvertedpixelsofimage:(uiimage *)image { uigraphicsbeginimagecontextwithoptions(image.size, no, 2); cgcontextsetblendmode(uigraphicsgetcurrentcontext(), kcgblendmodecopy); [image drawinrect:cgrectmake(0, 0, image.size.width, image.size.height)]; cgcontextsetblendmode(uigraphicsgetcurrentcontext(), kcgblendmodedifference); cgcontextsetfillcolorwithcolor(uigraphicsgetcurrentcontext(),[uicolor whitecolor].cgcolor); cgcontextfillrect(uigraphicsgetcurrentcontext(), cgrectmake(0, 0, image.size.width, image.size.height)); uiimage * result = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext();  return result; 

}

thank you!

this how solved.

it code can find in other answers, masking of current image same image, rotated context (for transforming cg* coords ui* coords).

- (uiimage *)invertimage:(uiimage *)originalimage {     uigraphicsbeginimagecontext(originalimage.size);     cgcontextsetblendmode(uigraphicsgetcurrentcontext(), kcgblendmodecopy);     cgrect imagerect = cgrectmake(0, 0, originalimage.size.width, originalimage.size.height);     [originalimage drawinrect:imagerect];       cgcontextsetblendmode(uigraphicsgetcurrentcontext(), kcgblendmodedifference);     // translate/flip graphics context (for transforming cg* coords ui* coords     cgcontexttranslatectm(uigraphicsgetcurrentcontext(), 0, originalimage.size.height);     cgcontextscalectm(uigraphicsgetcurrentcontext(), 1.0, -1.0);     //mask image     cgcontextcliptomask(uigraphicsgetcurrentcontext(), imagerect,  originalimage.cgimage);     cgcontextsetfillcolorwithcolor(uigraphicsgetcurrentcontext(),[uicolor whitecolor].cgcolor);     cgcontextfillrect(uigraphicsgetcurrentcontext(), cgrectmake(0, 0, originalimage.size.width, originalimage.size.height));     uiimage *returnimage = uigraphicsgetimagefromcurrentimagecontext();     uigraphicsendimagecontext();      return returnimage; } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -