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:
you create blank image, lock on it, drawing goes graphics context
nsimage *image = [[nsimage alloc] initwithsize:self.view.bounds.size]; [image lockfocus];
you draw layer same on ios
cgcontextref ctx = [nsgraphicscontext currentcontext].graphicsport; [self.view.layer renderincontext:ctx];
unlock image
[image unlockfocus];
note if view layered. doesn't work non-layered views!
view -as shown above- layer backed all's fine ;)
Comments
Post a Comment