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
Post a Comment