ios - invalid context 0x0, Creating UIImage from CALayer -
i trying convert calayer uiimage code post. copied here. when use got tons of error. @ first put in nsobject class use store model. read in post suppose put in controller, view or category of calayer. tried putting in controller or calayer , still doesn't work.
- (uiimage *)imagefromlayer:(calayer *)layer { if ([[uiscreen mainscreen] respondstoselector:@selector(scale)]) uigraphicsbeginimagecontextwithoptions([layer frame].size, no, [uiscreen mainscreen].scale); else uigraphicsbeginimagecontext([layer frame].size); [layer renderincontext:uigraphicsgetcurrentcontext()]; uiimage *outputimage = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); return outputimage; }
error:
<error>: cgcontextsetstrokecolorwithcolor: invalid context 0x0 <error>: cgcontextsetlinewidth: invalid context 0x0 <error>: cgcontextmovetopoint: invalid context 0x0 <error>: cgcontextaddarc: invalid context 0x0 <error>: cgcontextaddarc: invalid context 0x0 <error>: cgcontextaddarc: invalid context 0x0 <error>: cgcontextaddarc: invalid context 0x0 <error>: cgcontextclosepath: invalid context 0x0 <error>: cgcontextdrawpath: invalid context 0x0 <error>: cgcontextrestoregstate: invalid context 0x0 <error>: cgcontextrestoregstate: invalid context 0x0 <error>: cgcontextsetbasectm: invalid context 0x0 <error>: cgcontextrestoregstate: invalid context 0x0 <error>: cgcontextendtransparencylayer: invalid context 0x0 <error>: cgcontextrestoregstate: invalid context 0x0 <error>: cgcontextsavegstate: invalid context 0x0 <error>: cgcontextsetalpha: invalid context 0x0
check if layer parameter nil
. context cannot created if size has either width = 0 or height = 0 (or both).
Comments
Post a Comment