ios - how to save the image in system which is captured from UIGraphicsGetImageFromCurrentImageContext() in iPhone? -
hi want capture current uiview
image , store in local hard disc how can achieve:
example :
uigraphicsbeginimagecontext(self.superview.frame.size); [self.layer renderincontext:uigraphicsgetcurrentcontext()]; uiimage *backgroundimage = uigraphicsgetimagefromcurrentimagecontext();
i want store uiimage
in local drive in of png, jpeg format.
how can one. kindly me out. in advance.
the following code may achieve.
uigraphicsbeginimagecontext(self.superview.frame.size); [self.layer renderincontext:uigraphicsgetcurrentcontext()]; uiimage *image = uigraphicsgetimagefromcurrentimagecontext(); nsstring *stringpath = [[nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes)objectatindex:0]stringbyappendingpathcomponent:@"new folder"]; // new folder folder name nserror *error = nil; if (![[nsfilemanager defaultmanager] fileexistsatpath:stringpath]) [[nsfilemanager defaultmanager] createdirectoryatpath:stringpath withintermediatedirectories:no attributes:nil error:&error]; nsstring *filename = [stringpath stringbyappendingformat:@"/image.jpg"]; nsdata *data = uiimagejpegrepresentation(image, 1.0); [data writetofile:filename atomically:yes];
Comments
Post a Comment