objective c - How to take my view as a picture osx -


i want take nsview(with layers) image can in osx ?

in ios following

-(uiimage*) makeimage//snapshot view {     uigraphicsbeginimagecontext(self.view.bounds.size);     [self.view.layer renderincontext:uigraphicsgetcurrentcontext()];     uiimage *viewimage = uigraphicsgetimagefromcurrentimagecontext();     uigraphicsendimagecontext();     return viewimage; } 

i tried solution 1 of answers

[[nsimage alloc] initwithdata:[view datawithpdfinsiderect:[view bounds]]]; 

but didn't work because have layers in nsview.

i started converting ui ns , have warnings on every line :)

-(nsimage*) makeimage :(rmblurredview*)view {     uigraphicsbeginimagecontext(view.bounds.size);      [self.view.layer renderincontext:uigraphicsgetcurrentcontext()];      nsimage *viewimage = uigraphicsgetimagefromcurrentimagecontext();      uigraphicsendimagecontext();      return viewimage; } 

i not familiar osx can 1 me convert code osx ?

drawing image tad different in ios:

  1. you create blank image, lock on it, drawing goes graphics context

    nsimage *image = [[nsimage alloc] initwithsize:self.view.bounds.size]; [image lockfocus]; 
  2. you draw layer same on ios

    cgcontextref ctx = [nsgraphicscontext currentcontext].graphicsport; [self.view.layer renderincontext:ctx]; 
  3. unlock image

    [image unlockfocus]; 

note if view layered. doesn't work non-layered views!
view -as shown above- layer backed all's fine ;)


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -