ios - Do I need to call CGContextSaveGState and CGContextRestoreGState? -


double checking if need call cgcontextsavegstate , cgcontextrestoregstate when creating new imagecontext.

from i've read in quartz programming guide, shouldn't need in example below, because i'm creating brand new image context.

i've searched github uigraphicsbeginimagecontextwithoptions , folks save , restore context , other folks not.

// uses circularmask on image class func circularimage(image: uiimage, diameter: int) -> uiimage {     assert(diameter > 0, "diameter > 0 failed \(__function__)")      let frame = cgrect(x: 0.0, y: 0.0, width: double(diameter), height: double(diameter))     var newimage: uiimage?      uigraphicsbeginimagecontextwithoptions(frame.size, false, uiscreen.mainscreen().scale)      var context: cgcontextref = uigraphicsgetcurrentcontext()     cgcontextsavegstate(context)      let imagepath: uibezierpath = uibezierpath(ovalinrect: frame)     imagepath.addclip()      image.drawinrect(frame)      newimage = uigraphicsgetimagefromcurrentimagecontext()      cgcontextrestoregstate(context);      uigraphicsendimagecontext()      return newimage! } 

no, you're right don't need save context state you're doing there (and safely comment out ones have). if wanted 'undo' clipping did (for example) it's way that. careful keep these (save/restore)gstate in matching pairs, it's stack, must keep track of put on there.


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -