ios - How to load .png images from Documents folder of an app -
ios - How to load .png images from Documents folder of an app -
i have .png images in documents folder of app when seek load them don't work :/
i have class methods saving , loading :
uiimage+loadscan.h :
#import <uikit/uikit.h> @interface uiimage (loadscan) - (void)savescan:(nsstring*)name; - (uiimage *)loadscan:(nsstring*)name; @end
.m :
#import "uiimage+loadscan.h" @implementation uiimage (loadscan) #pragma save , load - (void)savescan:(nsstring*)name{ if (self != nil) { nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *documentsdirectory = [paths objectatindex:0]; nsstring* path = [documentsdirectory stringbyappendingpathcomponent: [nsstring stringwithstring:name] ]; nsdata* info = uiimagepngrepresentation(self); [data writetofile:path atomically:yes]; } } - (uiimage *)loadscan:(nsstring*)name{ nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *documentsdirectory = [paths objectatindex:0]; nsstring* path = [nsstring stringwithformat:@"%@/%@", documentsdirectory, name]; nslog(@"loading %@", path); nsdata *imgdata = [nsdata datawithcontentsoffile:path]; uiimage *image = [[uiimage alloc] initwithdata:imgdata]; //uiimage *image = [uiimage imagewithcontentsoffile:path]; homecoming image; } @end
the method savescan work :
[image savescan:[nsstring stringwithformat:@"%@.png", imgname]];
but loadscan don't want work :
uiimage *imageload = [[uiimage alloc] init]; [imageload loadscan:[nsstring stringwithformat:@"%@.png", imgname]]; cell.imagescan.image = imageload;
i don't understand why, yet file exist.
thanks
i have found (strange) method, work (i send uiimage united nations parametter , init in method) :
- (uiimage *)loadscan:(nsstring*)name theimage:(uiimage*)theimg{ nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *documentsdirectory = [paths objectatindex:0]; nsstring* path = [nsstring stringwithformat:@"%@/%@", documentsdirectory, name]; nslog(@"loading %@", path); [theimg initwithcontentsoffile:path]; homecoming theimg; }
call :
uiimage *imageload = [uiimage alloc]; [imageload loadscan:[nsstring stringwithformat:@"%@@2x.png", imgname] theimage:imageload];
now imageload have image info , can show !
ios objective-c iphone image
Comments
Post a Comment