0
是否可以將我從照片庫中選取的圖像保存到我的應用程序的主包中?我以爲我讀了一些地方,你不能寫入Xcode中的應用程序主包。如果這不是真的,那麼我該如何去做。從應用程序Xcode保存從照片庫到主包的圖像
是否可以將我從照片庫中選取的圖像保存到我的應用程序的主包中?我以爲我讀了一些地方,你不能寫入Xcode中的應用程序主包。如果這不是真的,那麼我該如何去做。從應用程序Xcode保存從照片庫到主包的圖像
Use this code to save image from photo Library to Main Bundle
- (void)saveImage:(UIImage*)image withImageName:(NSString*)imageName {
NSData *imageData = UIImagePNGRepresentation(image); //convert image into .png format.
NSFileManager *fileManager = [NSFileManager defaultManager];//create instance of NSFileManager
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //create an array and store result of our search for the documents directory in it
NSString *documentsDirectory = [paths objectAtIndex:0]; //create NSString object, that holds our exact path to the documents directory
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", imageName]]; //add our image to the path
[fileManager createFileAtPath:fullPath contents:imageData attributes:nil]; //finally save the path (image)
}