osx - Creating a png image from SpriteKit Node/SpriteNode in Xcode for Mac -


currently i'm making isometric map editor (in swift) each map tile added sknode called maplayer. want know whether possible produce png image maplayer, once have finished designing map?

not in swift should give idea on how it.

you can capture screen uiimage doing this:

cgrect bounds = self.scene.view.bounds; uigraphicsbeginimagecontextwithoptions(bounds.size, no, [uiscreen mainscreen].scale); [self drawviewhierarchyinrect:bounds afterscreenupdates:yes]; uiimage* screenshotimage = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); 

then create png image uiimage (and write disk) this:

// create paths output images nsstring  *pngpath = [nshomedirectory() stringbyappendingpathcomponent:@"documents/test.png"]; nsstring  *jpgpath = [nshomedirectory() stringbyappendingpathcomponent:@"documents/test.jpg"]; 

source here.

// write uiimage jpeg minimum compression (best quality) // value 'image' must uiimage object // value '1.0' represents image compression quality value 0.0 1.0 [uiimagejpegrepresentation(image, 1.0) writetofile:jpgpath atomically:yes];  // write image png [uiimagepngrepresentation(image) writetofile:pngpath atomically:yes];  // let's check see if files written...  // create file manager nserror *error; nsfilemanager *filemgr = [nsfilemanager defaultmanager];  // point document directory nsstring *documentsdirectory = [nshomedirectory() stringbyappendingpathcomponent:@"documents"];  // write out contents of home directory console nslog(@"documents directory: %@", [filemgr contentsofdirectoryatpath:documentsdirectory error:&error]); 

source here.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -