ios - CGImageCreateWithMaskingColors Does Not Mask on Apple Watch in WKInterfaceImage -
i've long since had snippet of code in iphone app attempts mask white background jpeg images. today, message still works on iphone, not mask whatsoever on apple watch. code runs on expected successful (non-null) path, no masking performed. if change maskingcolors array range 0.0, 255.0 each component, no masking performed (this same change on iphone masks image) when displayed in wkinterfaceimage (with setimage:).
png images alpha channel stored in asset catalog seem display on apple watch in wkinterfaceimage.
is cgimagecreatewithmaskingcolors not safe apple watch?
- (uiimage *)imagewithbackgroundremovedwithimagedata:(nsdata *)imagedata { cgimageref originalimage = [uiimage imagewithdata:imagedata].cgimage; /* attempt rgb images */ if (cgcolorspacegetmodel(cgimagegetcolorspace(originalimage)) != kcgcolorspacemodelrgb) return ([uiimage imagewithdata:imagedata]); /* mask 10 shades of "white" */ static const cgfloat maskingcolors[] = {245.0, 255.0, 245.0, 255.0, 245.0, 255.0}; cgimageref transparentimageref = cgimagecreatewithmaskingcolors(originalimage, maskingcolors); if (transparentimageref == null) return ([uiimage imagewithdata:imagedata]); uiimage *transparentimage = [uiimage imagewithcgimage:transparentimageref]; cgimagerelease(transparentimageref); return (transparentimage); }
this appears issue has existed since ios 7. see post more details: cgimagecreatewithmaskingcolors doesn't work ios7
using logic, i've modified code follows produce intended result:
uigraphicsbeginimagecontextwithoptions(transparentimage.size, no, 1.0); [transparentimage drawinrect:cgrectmake(0, 0, transparentimage.size.width, transparentimage.size.height)]; uiimage *anotherrendition = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); return (anotherrendition);
Comments
Post a Comment