簡體   English   中英

將照片從照片庫保存到應用Xcode中的Main Bundle

[英]Save an image from photo library to Main Bundle in app 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)
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM